本文介绍了如何在顶部选择select,在c#combobox中放在最后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框,我想在最后通过数据库检索它,并在组合框的顶部选择,并按字母表的升序在它们之间的所有其他条目请告诉我如何执行此操作

i have a combo box where i want to put other at the last while retrieving it through database and select at the top of combo box and all other entries in between them in ascending order of alphabet pls tell me how to do this

推荐答案

comboBox1.Items.Insert(0, "Select");
comboBox1.SelectedIndex = 0;


SqlCommand cmd = new SqlCommand("select count(*) from table", con);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
    count = int.Parse(dr[0].ToString());
    dr.Close();
}
comboBox1.Items.Insert(00, "select");
comboBox1.Items.Insert(count+1, "other");
comboBox1.SelectedIndex = 0;


这篇关于如何在顶部选择select,在c#combobox中放在最后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 01:11