要做一个comboBox控件与northwind中customers的字段CompanyName进行绑定,用以下代码实现的:
private void Form3_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server = (local);database = northwind;trusted_connection=yes");
string str4 = "Select CompanyName from customers ";
string a = str4.ToString();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(str4 ,conn);
da.Fill(ds ,"customers");
comboBox1 .DataSource = ds .Tables ["customers"].DefaultView ;
comboBox1.DisplayMember = a ;
}执行的结果是显示出来多行
System.Data.DataRowView
不知道是哪句写的有问题,哪位做过请给予指教。
private void Form3_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server = (local);database = northwind;trusted_connection=yes");
string str4 = "Select CompanyName from customers ";
string a = str4.ToString();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(str4 ,conn);
da.Fill(ds ,"customers");
comboBox1 .DataSource = ds .Tables ["customers"].DefaultView ;
comboBox1.DisplayMember = a ;
}执行的结果是显示出来多行
System.Data.DataRowView
不知道是哪句写的有问题,哪位做过请给予指教。
comboBox1 .DataSource = ds .Tables ["customers"];