0

Update requires a valid DeleteCommand when passed DataRow collection with deleted rows. This is the error I get when I'm deleting a row in my datagrid. I referred my code to a running program but when I embedded it on my own it occured that way. Here's the code:

myConn.Open();
            dTable = new DataTable("Records");
            dTable = this.ds.Tables[0];
            int i = this.iRowIndex;
            dTable.Rows[i].Delete();
            this.da.Update(dTable);

Any suggestions?

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by harcaype
0

Before calling the update() method of the data Adapter call the acceptchanges of the datatable
type dTable.AcceptChanges(); i.e

myConn.Open();
        dTable = new             DataTable("Records");
            dTable = this.ds.Tables[0];
            int i = this.iRowIndex;
            dTable.Rows[i].Delete();
dTable.AcceptChanges();
this.da.Update(dTable);

hope this help.

0

thanks! it worked! however. it does not affect the database itself. how can I make it delete from there too?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.