Sql server 2008 用c语言将windows窗体控件绑定到sql server数据
我已将combobox绑定到数据源。我是通过组合框属性来实现的。我还将文本框绑定到同一数据源。当尝试更改combobox中的项目时,它会更改textbox中的值。但当我尝试从组合框中选择另一项时,它会给出错误 这会导致集合中的两个绑定绑定到同一个属性。 参数名称:绑定 这是绑定文本框的代码Sql server 2008 用c语言将windows窗体控件绑定到sql server数据,sql-server-2008,c#-4.0,Sql Server 2008,C# 4.0,我已将combobox绑定到数据源。我是通过组合框属性来实现的。我还将文本框绑定到同一数据源。当尝试更改combobox中的项目时,它会更改textbox中的值。但当我尝试从组合框中选择另一项时,它会给出错误 这会导致集合中的两个绑定绑定到同一个属性。 参数名称:绑定 这是绑定文本框的代码 private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { con.Open()
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from ProductMaster", con);
DataSet ds = new DataSet();
da.Fill(ds, "ProductMaster");
textBox5.DataBindings.Add("text", ds, "ProductMaster.Rate");
label17.DataBindings.Add("text", ds, "ProductMaster.VAT");
con.Close();
}
请帮助每次都应清除绑定。因为每次您在组合框中选择一个新项目时,此事件都会将数据源绑定到组合框,并且由于它以前已与您以前选择的项目绑定,因此会给出错误。同样的问题昨天也发生在我身上,我通过在每次新绑定之前清除绑定来解决 这是我的代码:
private void cmb_aye_SelectedIndexChanged(object sender, EventArgs e)
{
OleDbDataAdapter da_select = new OleDbDataAdapter(string.Format("SELECT * FROM quran WHERE (sure={0} and aye={1})", cmb_sure.SelectedItem.ToString(), cmb_aye.SelectedItem.ToString()), objConnection);
DataTable dt = new DataTable();
dt.Clear();
da_select.Fill(dt);
txt_tarjome.DataBindings.Clear();
txt_tarjome.DataBindings.Add("Text", dt, "tarjome");
txt_matn_aye.DataBindings.Clear();
txt_matn_aye.DataBindings.Add("Text", dt, "baerab");
}