如何使用BindingSource.AddNew添加數據
BindingSource mbs = new BindingSource();
DataTable mdtProducts = new DataTable();
mbs.DataSource = mdtProducts;
Binding GUIDBinding = new Binding( "Text ", mbs , "empGUID ");
Binding IDBinding = new Binding( "Text ", mbs , "empID ");
Binding NameBinding = new Binding( "Text ", mbs , "empName ");
Binding MaleBinding = new Binding( "Text ", mbs , "empIsMale ");
txtGUIDR.DataBindings.Add(GUIDBinding);
txtID.DataBindings.Add(IDBinding);
txtName.DataBindings.Add(NameBinding);
txtMale.DataBindings.Add(MaleBinding);
我是利用BindingSource 作數據源,TextBox控件都與此數據源綁定!
我現在想想利用BindingSource.AddNew來添加數據,
控件和數據源是綁定好的,所以在添加的時候應該是根據綁定控件TextBox中的值來自動添加到數據庫相應的字段中,可是找了好久的資料都沒有自動添加的,都是要手動賦值的,比如BindingSource.Add(TextBox1.Text);
有沒有不需要賦值而是自動根據綁定控件添加數據的,求教高手!
謝謝大家了!
------解决方案--------------------直接AddNew()