treatment of duplicate records by sqldataadapter

I use sqldataadapter to add several records to a database.  Some, but not all, of those records may already be included in the source table and may contravene the primary key or unique index.  It seems that when I call sqldataadapter.update it will insert all records until it hits the first duplicate and then insert no more valid (non-duplicate) trades after that point.  What I want it to do is insert all records but ignore, or skip over, the duplicates.  What is the best way for me to achieve this.


Who is Participating?
Juan_BarreraConnect With a Mentor Commented:
Hi nick,

Try by setting the DataAdapter to:  

da.ContinueUpdateOnError = False

I think it should help you with the problem.
Fernando SotoConnect With a Mentor RetiredCommented:
Hi nicksbell;

On the DataAdpater set the ContinueUpdateOnError property to true.

From the Microsoft Documentation:
If ContinueUpdateOnError is set to true, no exception is thrown when an error occurs during the update of a row. The update of the row is skipped and the error information is placed in the RowError property of the row in error. The DataAdapter continues to update subsequent rows.

You should check RowError property of the row to check the rows that had an error.


Nick, now that I read Fernando's comment I see my error. Obviously it should be

da.ContinueUpdateOnError = True

Anyway, that's the property you should set.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.