在C#中怎么把SQL数据库中查询的结果以表格的形式显示到Windows窗体上,我添加了一个DataGridView控件
查询条件:selectGnoas编号,Gnameas名称,Gpriceas单价,Squaas库存量,Stopas最大量,Sbaseas最小量fromstor_goods,...
查询条件: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");
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");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询