根据名称从数据库填充到组合框的数据...
SqlConnection con = new SqlConnection(@"Data Source=CENTAUR09-PC\SQLEXPRESS;Initial Catalog=Sample;Integrated Security=true");
SqlCommand cmd = new SqlCommand("Select cust_name from customer", con);
con.Open();
comboBox1.DataSource = cmd;
comboBox1.DisplayMember = cmd.ToString();
con.Close();
......数据源和显示成员是什么?
答案 0 :(得分:3)
这样的事情:
DataTable dt = new DataTable();
using(SqlConnection con = new SqlConnection(@"Data Source=CENTAUR09-PC\SQLEXPRESS;Initial Catalog=Sample;Integrated Security=true"))
{
SqlCommand cmd = new SqlCommand("Select id, cust_name from customer", con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(dt);
comboBox1.DataSource = dt.DefaultView;
comboBox1.DisplayMember = "cust_name";
comboBox1.ValueMember = "id";
}
修改强>
最好选择客户PK并将其路径设置为VlaueMember