在C#中怎么把SQL数据库中查询的结果以表格的形式显示到Windows窗体上,我添加了一个DataGridView控件

查询条件:select Gno as 编号,Gname as 名称, Gprice as 单价,Squa as 库存量,Stop as 最大量,Sbase as 最小量 from stor_goods,goods_info where SGno=Gno and SCno=101
怎么把这个条件写到那个控件的函数里面去实现呢?
这个问题之前就有人在度娘上问过的了,但是看回答的内容我还是不满意啊!!求大大们给个代码吧!!!回答好的我可以加分的!!!急求!!!

//连接你的数据库
string connstr = "server=.;uid=sa;pwd=sa;database=sc";
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sqlsel, conn);
da.Fill(ds, "coust");
DataTable dt = ds.Tables["coust"];
conn.Close();
return dt;

// TODO: 这行代码将数据加载到表“studentDataSet.studentinfo”中。您可以根据需要移动或移除它。
//this.studentinfoTableAdapter.Fill(this.studentDataSet.studentinfo);
//数据绑定
string sqlsel = "select * from studentinfo ";
DataTable dt = bangding(sqlsel);
cmAmend = (CurrencyManager)BindingContext[dt];
this.dataGridView1.DataSource = dt;
this.textBox1.DataBindings.Add("text", dt, "sno");
this.textBox2.DataBindings.Add("text", dt, "sname");
this.textBox3.DataBindings.Add("text", dt, "ssex");
this.textBox4.DataBindings.Add("text", dt, "sage");
this.textBox5.DataBindings.Add("text", dt, "sclass");
this.textBox6.DataBindings.Add("text", dt, "sdept");
this.textBox7.DataBindings.Add("text", dt, "saddress");
this.textBox8.DataBindings.Add("text", dt, "sphone");
this.textBox9.DataBindings.Add("text", dt, "sqq");
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-04-21
用DataGridView的DataSource绑定数据集里的数据表就ok了追问

这样的回答真的不是我想要的

追答

自己研究下就知道了。绑定数据算比较基础的东西

相似回答