DataAdapter.Fill & AutoIncrement -> ConstraintException

J

James Cadd

DataLayer's steps:
1. DataAdapter.Update(dtUserChanges)
2. DataAdapter.Fill(dtUserChanges)

I'm having trouble with DataAdapter.Fill creating
duplicate rows in a table which has an AutoIncrement
primary key. When it happens, I get a
ConstraintException thrown from the Fill method. I know
it's happening because, to keep the DataSet mergeable, I
handle DataAdapter.RowUpdating and set
sqlRowUpdatedEventArgs.Status =
UpdateStatus.SkipCurrentRow. What's a good way to deal
with this problem?
 
J

James Cadd

Ok, I fixed this by handling the DataTable.RowChanging
event and throwing an exception if a row was added with a
primary key value that already exists in the DataTable
(to prevent the row from being added). Is there a better
way?? It would be nice if DataAdapter.Fill could just
look at the current versions of the rows instead of the
original versions. Any guidance would be appreciated, I
feel like I've found enough rope to hang myself with!
 

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

Top