使用DataGridView更新数据库 习惯了BCB 中的Dbgrid 的方便操作,想在VS C#里也这样,可是还真是不容易.费了好大功夫,总算好一点了不过感觉挺麻烦的.这个DataGridView很不省事.可以通过点击按钮,来提交数据了... public partial class Form1 : Form {Form1数据成员#region Form1数据成员 private DataTable DT = new DataTable(); private SqlDataAdapter SDA = new SqlDataAdapter();#endregionForm1构造函数#region Form1构造函数 public Form1() { InitializeComponent(); }#endregion连接数据库显示数据#region 连接数据库显示数据 private void Form1_Load(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("server=127.0.0.1;database=pubs;uid=sa"); SqlCommand SCD = new SqlCommand("select * from tables", conn); SDA.SelectCommand = SCD; SDA.Fill(DT); dataGridView1.DataSource = DT; }#endregion使用Update更新数据库#region 使用Update更新数据库 private void toolStripButton1_Click(object sender, EventArgs e) { try { SqlCommandBuilder SCB = new SqlCommandBuilder(SDA); SDA.Update(DT); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } MessageBox.Show("更新成功!"); }#endregion