ADO.NET problem: RejectChanges not Working

  • 15 years ago

    I am having a problem with cancelling added records.  Here is the problem:

    (1) I have a STATE table (in Oracle) with two columns - a two-letter state code that serves as the primary key, and a dull state name column - that I use to fill a dataset using a dataadapter
    (2) I add a row to the dataset
    (2) I invoke the dataadapter's update method to push changes in the dataset to the database
    (3) If the record does not violate a unique constraint for the primary key, the record is inserted successfully.  On the other hand, if it violates the unique constraint of the primary key, I trap the error and invoke the dataset table's RejectChanges method.  

    This all seems to work - the reject changes gets rid of the row in the dataset (the dataset's recordcount goes down by 1 after invoking the RejectChanges method).  The problem comes when I subsequently try to add a record that does not violate the unique constraint of the primary key - it raises an error saying that I'm violating it anyway.  If I stop and restart the application and try to add it without first entering a bad record, it accepts it.

    Is my dataset still secretly storing the rejected record?  Or is it that I have to clear the error out somehow?  HELP!

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.”