C#中怎样将数据库查询出来的数据放进combobox下拉列表中

2024-11-22 10:41:18
推荐回答(1个)
回答1:

SqlConnection Conn=....
//初始化,comboBox1绑定客户表
string Sql= "select customerName from customer";
DataSet Ds= new DataSet();
SqlDataAdapter Da= new SqlDataAdapter(Sql, Conn);
Da.Fill(Ds, "customer");
comboBox1.DataSource = Ds.Tables["customer"];
comboBox1.DisplayMember = "customerName";