急!求救,2005中用BindingSource把数据绑定到TextBox控件怎样保存?
private DataSet ds = new DataSet();
private BindingSource BindingSource1 = new BindingSource();
private SqlCommandBuilder SqlCommandBuilder1;
private SqlDataAdapter da;
private SqlConnection cn;
string cmdtext = "select XH1,KHBM,ZBXH_KFLB,ZWMC,LXR,LXDH,DZ,SFZS,ZBXH_YWY,REMARK,ZDR,ZDRQ from JCZL_KHBM_M where XH1 = " + xhh;
da = new SqlDataAdapter(cmdtext, cn);
SqlCommandBuilder1 = new SqlCommandBuilder(da);
da.Fill(ds);
BindingSource1.DataSource = ds;
this.textBox1.DataBindings.Add( "text ", ds.Tables[0], "XH1 ");
this.textBox2.DataBindings.Add( "text ", ds.Tables[0], "KHBM ");
this.textBox3.DataBindings.Add( "text ", ds.Tables[0], "ZBXH_KFLB ");
this.textBox4.DataBindings.Add( "text ", ds.Tables[0], "ZWMC ");
this.textBox5.DataBindings.Add( "text ", ds.Tables[0], "LXR ");
this.textBox6.DataBindings.Add( "text ", ds.Tables[0], "LXDH ");
this.textBox7.DataBindings.Add( "text ", ds.Tables[0], "DZ ");
this.textBox8.DataBindings.Add( "text ", ds.Tables[0], "ZBXH_YWY ");
this.textBox9.DataBindings.Add( "text ", ds.Tables[0], "REMARK ");
this.textBox10.DataBindings.Add( "text ", ds.Tables[0], "ZDR ");
this.textBox11.DataBindings.Add( "text ", ds.Tables[0], "ZDRQ ");
this.checkBox1.DataBindings.Add( "Checked ", ds.Tables[0], "SFZS ");
this.comboBox1.DataBindings.Add( "text ", ds.Tables[0], "ZBXH_KFLB ");
这样子绑定,修改后用以下语句保存:
BindingSource1.EndEdit();
da.Update(ds, "JCZL_KHBM_M ");或者直接用da.Update(ds);