Problem with DataRowCollection.RemoveAt() and OleDbDataAdapter.Upd

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have encountered the following problem.

Say I have the following,

DataGridView dgv;
DataTable dt;
OleDbDataAdapter oleDb_da; (bound to a OleDb data connection)

dt is the bounded data source of dgv, and I use oleDb_da.Fill(dt) to fill
the data table.

If I execute dt.Rows.RemoveAt(row_index), the row is removed, instead of
marked delete. When I run oleDb_da.Update(), my database is corrupted since
the deleted row is not updated in my database.

When I simply delete a row from my DataGridView dgv, the deleted row is
still in the collection, but marked deleted. When I run oleDb_da.Update(),
everything works correctly. I assume DataGridView delete (e.g. select a row
and click the button delete), must have execute DataRow.Delete().

Has anyone encountered above? Does anyone have an answer why
DataRowCollection.RemoveAt() fails in this scenario?

Thanks,
 
Hi George,

Thanks for your post!

Based on my experience DataGridView internally calls DataRow.Delete method
to delete that row, so the database updating will reflect the delete
operation. DataRowCollection.RemoveAt method will remove this row from the
row collection, so the database updating will not touch that row in the
database at all.

So, to update the database row deletion programmatically, I recommended you
to use DataRow.Delete method.

Hope it helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi George,

Have you got my reply? Is your problem resolved? Please feel free to tell
me, thanks!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top