Home > Uncategorized > ADO.net DataSet – Watch out for AcceptChanges – Don’t do before Update

ADO.net DataSet – Watch out for AcceptChanges – Don’t do before Update

I’ve been recently writing a small program in ADO.net, using DataSet classes (using Visual Studio dataset designer) to import Biblionet data on greek books into an osCommerce shop (MySQL database) and was wandering why it seemed to work ok, but never wrote anything in the database.

I started wandering whether it was an issue with the MySQL .NET Connector (this is ver 6.0, see latest versions of MySQL Connectors), when I noticed a oscDataset.AcceptChanges() command right before oscSomeTableAdapter.Update(oscDataset.oscSomeTable). DataTableAdapter classes generated by the custom tool associated in Visual Studio to DataSet schema files are used to do the real changes in the database.

Of course that was marking the dataset as “non-dirty” (not having any pending changes to upload) and the Update commands of the various table adapters I was calling were doing no changes (row insertions or updates) since the dataset gave them none. Just moved that command after the Update and in fact commented it out since I don’t really need to use the dataset anymore after the update, just exiting the application after the import is finished.

Categories: Uncategorized Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: