1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using System.Data.SqlClient; 10 11 namespace WinFom 12 { 13 public partial class Form1 : Form 14 { 15 private DataTable DT = new DataTable(); 16 private SqlDataAdapter SDA = new SqlDataAdapter(); 17 18 public Form1() 19 { 20 InitializeComponent(); 21 } 22 23 private void Form1_Load(object sender, EventArgs e) 24 { 25 SqlConnection con = new SqlConnection("Data Source=192.168.18.10;Initial Catalog=PMDATA;User ID=sa;Password=a"); 26 SqlCommand cmd = new SqlCommand("Select DEPT_NO,DEPT_NM,CREATE_DATE,CREATE_BY From B_DEPT",con); 27 SDA.SelectCommand = cmd; 28 SDA.Fill(DT); 29 superGridControl1.PrimaryGrid.DataSource = DT; 30 } 31 private void GridSave(object sender, EventArgs e) 32 { 33 SqlCommandBuilder SCB = new SqlCommandBuilder(SDA); 34 SDA.Update(DT); 35 } 36 37 } 38 }
就是这样生成的!
我也有个疑问。。听说Dataadapter的UPDATE方法会一条一条更新验证,帮助上也说要用GetChange,请问保存有更优化的方法吗?有大神指教下我这个小菜鸟吗?
我又问了一些高手,改良了下GridSave事件
private void GridSave(object sender, EventArgs e) { DataTable dtchange = DT.GetChanges(); SqlCommandBuilder SCB = new SqlCommandBuilder(SDA); SDA.Update(dtchange); }