2个回答
2013-09-22
展开全部
//combobox和dataGD的绑定数据库
private void Form1_Load(object sender, System.EventArgs e)
{
//在formload时绑定数据表yg到comboBox1
SqlConnection conn=new SqlConnection("server=.;uid=sa;pwd=;database=gz");
SqlDataAdapter da=new SqlDataAdapter("select * from yg",conn);
DataSet ds=new DataSet();
da.Fill(ds,"yg");
this.comboBox1.DataSource=ds.Tables["yg"];
this.comboBox1.DisplayMember="ygname"; //显示的列
this.comboBox1.ValueMember="ygid"; //数据列,次列会在selectedvalue中显示
}
//要在不同的方法中使用同一个数据集就要把数据集改成全局
DataSet ds1=new DataSet();
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
SqlConnection conn=new SqlConnection("server=.;uid=sa;pwd=;database=gz");
//根据comboBox的选择写查询语句
try
{
SqlDataAdapter da=new SqlDataAdapter("select * from gz inner join yg on yg.ygid=gz.ygid where gz.ygid="+this.comboBox1.SelectedValue.ToString(),conn);
da.Fill(ds1,"gza");
this.dataGrid1.DataSource=ds1.Tables["gza"].DefaultView;
}
catch
{}
}
private void dataGrid1_Click(object sender, System.EventArgs e)
{
//通过datagrid中选中的行号来得到dataSet中的数据
this.textBox1.Text=ds1.Tables["gza"].Rows[this.dataGrid1.CurrentRowIndex]["gzid"].ToString();
this.textBox2.Text=ds1.Tables["gza"].Rows[this.dataGrid1.CurrentRowIndex]["gznum"].ToString();
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
//在formload时绑定数据表yg到comboBox1
SqlConnection conn=new SqlConnection("server=.;uid=sa;pwd=;database=gz");
SqlDataAdapter da=new SqlDataAdapter("select * from yg",conn);
DataSet ds=new DataSet();
da.Fill(ds,"yg");
this.comboBox1.DataSource=ds.Tables["yg"];
this.comboBox1.DisplayMember="ygname"; //显示的列
this.comboBox1.ValueMember="ygid"; //数据列,次列会在selectedvalue中显示
}
//要在不同的方法中使用同一个数据集就要把数据集改成全局
DataSet ds1=new DataSet();
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
SqlConnection conn=new SqlConnection("server=.;uid=sa;pwd=;database=gz");
//根据comboBox的选择写查询语句
try
{
SqlDataAdapter da=new SqlDataAdapter("select * from gz inner join yg on yg.ygid=gz.ygid where gz.ygid="+this.comboBox1.SelectedValue.ToString(),conn);
da.Fill(ds1,"gza");
this.dataGrid1.DataSource=ds1.Tables["gza"].DefaultView;
}
catch
{}
}
private void dataGrid1_Click(object sender, System.EventArgs e)
{
//通过datagrid中选中的行号来得到dataSet中的数据
this.textBox1.Text=ds1.Tables["gza"].Rows[this.dataGrid1.CurrentRowIndex]["gzid"].ToString();
this.textBox2.Text=ds1.Tables["gza"].Rows[this.dataGrid1.CurrentRowIndex]["gznum"].ToString();
}
}
2013-09-22
展开全部
c#语言里是combox.binding=“”
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询