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;上面是我用的读取数据的方法,请问大家如何来实现数据的更新啊,我修改或者添加数据后,发现数据库里面的数据并没有更新,请教达人指点,谢谢。
我是肉鸟。
myConnection.Open();
adapter.SelectCommand = new SqlCommand("***", myConnection);
adapter.Fill(table);
bindingSourceBS.DataSource = table;
dtGridView.AutoGenerateColumns = false;
myConnection.Close();dtGridView.DataSource = bindingSourceBS;上面是我用的读取数据的方法,请问大家如何来实现数据的更新啊,我修改或者添加数据后,发现数据库里面的数据并没有更新,请教达人指点,谢谢。
我是肉鸟。
{
try
{
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
adapter.UpdateCommand = builder.GetUpdateCommand();
adapter.Update(table);
MessageBox.Show("更新成功!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}我是这样写的,可是只能修改,不能增加数据,谢谢各位了,说的明白一点,我是新手啊。
{
try
{
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
//adapter.UpdateCommand = builder.GetUpdateCommand();
adapter.Update(table);
MessageBox.Show("更新成功!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
adapter.InsertCommand = builder.GetInsertCommand();
adapter.DeleteCommand = builder.GetDeleteCommand();
adapter.UpdateCommand = builder.GetUpdateCommand();
adapter.Update(table);