请问如何把ComboBox绑定数据库??
数据库:select userid,username from userinfoComboBox:显示username
提交后得到相应的值是userid
谢谢 我是新学 希望详细些 --------------------编程问答-------------------- up --------------------编程问答-------------------- this.comboBox1.DataSource = ds.Tables[0];
this.comboBox1.DisplayMember = "username";
this.comboBox1.ValueMember = "userid"; --------------------编程问答-------------------- 以SQLSERVER为例
String checksql = "select userid,username from userinfo";
conn.Open();
System.Data.SqlClient.SqlDataAdapter sqlda;
DataSet dt = new DataSet();
sqlda = new SqlDataAdapter(checksql, conn);
sqlda.Fill(dt,"dt_set");
在界面层:
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
this.clb.Items.Add(ds.Tables["dt_set"].Rows[i]["name"].ToString());
}
--------------------编程问答-------------------- this.comboBox1.DataSource = ds.Tables[0];
this.comboBox1.DisplayMember = "username";
this.comboBox1.ValueMember = "userid";
--------------------编程问答-------------------- this.comboBox1.DataSource = ds;
this.comboBox1.DisplayMember = "username";
this.comboBox1.ValueMember = "userid"; --------------------编程问答-------------------- 晕死
咋不把全部代码拷出来
就那么一点
补充:.NET技术 , C#