1. 程式人生 > >綁定下拉框

綁定下拉框

box n) nec adapter his sql apt isp con

string count = "Data Source=.;Initial Catalog=123;User ID=sa;pwd=123456";
SqlConnection conn = new SqlConnection(count);

conn.Open();
DataTable da = new DataTable();
string sql = "SELECT [xingming] ,[xuehao] FROM [dbo].[456]";
SqlDataAdapter dt = new SqlDataAdapter(sql, conn);
dt.Fill(da);

this.comboBox1.ValueMember = "xuehao";
this.comboBox1.DisplayMember = "xingming";
this.comboBox1.DataSource = da;

綁定下拉框