我正在尝试更新DataGrid
中的记录,但我收到以下错误消息:
在传递带有修改行的DataRow集合时,更新需要有效的UpdateCommand
以下是我的代码:
private void btnUpdate_Click(object sender, EventArgs e)
{
System.Data.DataTable dt = ds.Tables["tblImpi"];
this.impdg.BindingContext[dt].EndCurrentEdit();
this.dataAdapter.Update(dt);
MessageBox.Show("Update Successful");
}
答案 0 :(得分:0)
试试这个:
SqlDataAdapter adapter;
DataSet ds;
public void ReadData()
{
this.ds = new DataSet())
this.adapter = new SqlDataAdapter(query, conString))
adapter.Fill(thisds, "TABLE1");
this.ds.AcceptChanges();
this.dataGridView1.DataSource = ds.DefaultViewManager;
}
public void SaveData()
{
using (DataSet changes = this.ds.GetChanges())
{
if (changes != null)
{
int updatedRows = this.dataAdapter.Update(changes);
this.ds.AcceptChanges();
}
}
}
private void btnUpdate_Click(object sender, EventArgs e)
{
SaveData();
}