Deleting rows in datagrid

Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2008
Posts: 31
Reputation: harcaype is an unknown quantity at this point 
Solved Threads: 0
harcaype harcaype is offline Offline
Light Poster

Deleting rows in datagrid

 
0
  #1
Jul 11th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 22
Reputation: ema005 is an unknown quantity at this point 
Solved Threads: 4
ema005 ema005 is offline Offline
Newbie Poster

Re: Deleting rows in datagrid

 
0
  #2
Jul 14th, 2008
Before calling the update() method of the data Adapter call the acceptchanges of the datatable
type dTable.AcceptChanges(); i.e
  1. myConn.Open();
  2. dTable = new DataTable("Records");
  3. dTable = this.ds.Tables[0];
  4. int i = this.iRowIndex;
  5. dTable.Rows[i].Delete();
  6. dTable.AcceptChanges();
  7. this.da.Update(dTable);
hope this help.
Last edited by Tekmaven; Jul 14th, 2008 at 11:04 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 31
Reputation: harcaype is an unknown quantity at this point 
Solved Threads: 0
harcaype harcaype is offline Offline
Light Poster

Re: Deleting rows in datagrid

 
0
  #3
Jul 15th, 2008
thanks! it worked! however. it does not affect the database itself. how can I make it delete from there too?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum


Views: 4130 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC