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?

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.