SqlConnection myConnection = new SqlConnection(connectionString);
            myConnection.Open();
            adapter.SelectCommand = new SqlCommand("***", myConnection);
            adapter.Fill(table);
            bindingSourceBS.DataSource = table;
            dtGridView.AutoGenerateColumns = false;
            myConnection.Close();dtGridView.DataSource = bindingSourceBS;上面是我用的读取数据的方法,请问大家如何来实现数据的更新啊,我修改或者添加数据后,发现数据库里面的数据并没有更新,请教达人指点,谢谢。
我是肉鸟。

解决方案 »

  1.   

    参看http://community.csdn.net/Expert/topic/5771/5771415.xml?temp=.8575556代码不贴了
      

  2.   

    private void toolStripButtonSave_Click(object sender, EventArgs e)
            {
                try
                {
                    SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
                    adapter.UpdateCommand = builder.GetUpdateCommand();
                    adapter.Update(table);
                                    MessageBox.Show("更新成功!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }我是这样写的,可是只能修改,不能增加数据,谢谢各位了,说的明白一点,我是新手啊。
      

  3.   

    private void toolStripButtonSave_Click(object sender, EventArgs e)
            {
                try
                {
                    SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
                    //adapter.UpdateCommand = builder.GetUpdateCommand();
                    adapter.Update(table);
                                    MessageBox.Show("更新成功!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
      

  4.   

    SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
    adapter.InsertCommand = builder.GetInsertCommand();
    adapter.DeleteCommand = builder.GetDeleteCommand();
    adapter.UpdateCommand = builder.GetUpdateCommand();
    adapter.Update(table);