[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 524
  • Last Modified:

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.

Thanks

0
nicksbell
Asked:
nicksbell
  • 2
2 Solutions
 
Juan_BarreraCommented:
Hi nick,

Try by setting the DataAdapter to:  

da.ContinueUpdateOnError = False

I think it should help you with the problem.
0
 
Fernando SotoCommented:
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.

Fernando

0
 
Juan_BarreraCommented:
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.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now