2014-09-22 119 views
0

我在C#項目中使用訪問數據庫。我也有一個DataGridView來顯示和編輯表格。當我添加新行時它工作正常,但刪除/編輯現有行時出現異常。
Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.
的relavent代碼:DataGridview不會更新/刪除

private void updateB_Click(object sender, EventArgs e) 
{ 
    this.complaintsTableAdapter.Update(this.databaseDataSet.complaints); 
    this.complaintsTableAdapter.Fill(this.databaseDataSet.complaints); 

} 
+1

閱讀一些教程 – Vland 2014-09-22 07:31:17

回答

2

必須在complaintsTableAdapter
TableAdpater設置一些設置中設置InsertUpdateDelete命令,或者如果你從設計師自動創建表適配器可以使用
Create method to send updates directly to the database (GenerateDBDirectMethods)

這可以解決您的問題