c# listbox控件读取出数据库中的数据。
1个回答
展开全部
SqlConnection sqlcon;
SqlDataAdapter sqlada;
sqlcon = new SqlConnection("Data Source=.\\press;Initial Catalog=HQZPOSDB;User ID=sa;Password=zenii");
sqlcon.Open();
string str = "select goodsname1 from goods";
sqlada = new SqlDataAdapter(str, sqlcon);
DataSet a = new DataSet();
sqlada.Fill(a);
listBox1.DisplayMember = "goodsname1";
listBox1.ValueMember = "goodsname1";
listBox1.DataSource = a.Tables[0].DefaultView;
很简单的一个绑定 ..希望能帮到你..
SqlDataAdapter sqlada;
sqlcon = new SqlConnection("Data Source=.\\press;Initial Catalog=HQZPOSDB;User ID=sa;Password=zenii");
sqlcon.Open();
string str = "select goodsname1 from goods";
sqlada = new SqlDataAdapter(str, sqlcon);
DataSet a = new DataSet();
sqlada.Fill(a);
listBox1.DisplayMember = "goodsname1";
listBox1.ValueMember = "goodsname1";
listBox1.DataSource = a.Tables[0].DefaultView;
很简单的一个绑定 ..希望能帮到你..
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询