Error Exception when inserting duplicate record into table

I am parsing out a text file.  I have loaded the fields into a an Array of Arrays.  RecordArray( )( )

On a rare occasion my text file contains a duplicate record.

I am using a for next loop

For Y = 0 to RecordArray.GetUpperBound(0)
Insert Into Blah Blah Blah
Next


When I go to insert the record in the table I get error #2627 which I catch in a try catch block.  How can I use the Catch Block that if it is an error #2627 that we increment Y and continue processing the next record.

Thanks In advance

Dan
DigitalDan3Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
What type of exception do you get (i.e. ArgumentOutOfRangeException, SqlException, etc.)?

There might be a better way, using a hash table to load data, instead of using a Try...Catch block.

Bob
DigitalDan3Author Commented:
System.Data.SqlClient.SqlException #2627

Bob LearnedCommented:
Dim done As Boolean = False

While Not done

  Try

     ' Perform stuff here.

     done = True

  Catch ex As SqlException

     If ex.Number = 2627 Then
        y +=1
     End If

  End Try

End While
   

Bob

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DigitalDan3Author Commented:
Almost Works.  Problem is it resets my for next to Y =  0 to blah blah blah
I ended up declaring z as integer = 0


Dim done As Boolean = False
Dim z as Integer = 0
Dim y as Integer = 0

While Not done

  Try
     For y = z to array.getupperbound(0)
     ' Perform stuff here.
     Next y
     done = True

  Catch ex As SqlException

     If ex.Number = 2627 Then
        z +=1
     End If

  End Try

End While
Bob LearnedCommented:
Dim count As Integer = array.Length - 1
Dim z as Integer = 0

For y As Integer = z to count

     Try

        ' Perform stuff here.

     Catch ex As SqlException

        If ex.Number = 2627 Then
          z +=1
        Else
          Exit For
        End If

     End Try

Next y

Bob
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.