tags:

views:

72

answers:

2

Hello,

I am looping through several hundred records from a XML file and inserting in SQL server 2008 using LinQ from my Web Service.

My question is, for some reason if a record is not inserted it is coming out of the loop and going to the Catch block directly.

How do I move to the next record if the insert fails and continue with the other records?

Thanks in advance

A: 

Move or create a catch block inside the loop

Alfred Myers
A: 

I'm assuming that your code looks something like:

Try
  For Each record As YourClass In yourCollection
    ' Code to insert record goes here.
  Next
Catch
End Try

You will need to add a try-catch block inside the loop. Depending on your intentions it may be acceptable to leave the outer try-catch block.

For Each record As YourClass In yourCollection
  Try 
    ' Code to insert record goes here.
  Catch
  End Try
Next
Brian Gideon