Tableadapter error handling

I have a sinking feeling I'm not going to like the answer to this one. In short, I'm inserting a large number of rows into a database. I want to ignore any primary key violation errors (discard the row) and continue the tableAdapter.Update operation. Is there a way to do this I am using a strongly typed dataset in VS2005.

Thanks,

Bob



Answer this question

Tableadapter error handling

  • Lixin D

    ...omg Coach24 I soooooo owe you a beer... Thanks for posting this!


  • Big Ben

    I have found the solution. I extended the tableadapter class and then used the RowUpdated event to trap and ignore the primary key error:

    Namespace TruckTrackingDataSetTableAdapters

    Partial Class RFIDactivityTableAdapter

    Private ERRPRIMARYKEY As Integer = 2627

    Public Sub Adapter_RowUpdated(ByVal sender As Object, ByVal e As SqlRowUpdatedEventArgs) Handles _adapter.RowUpdated
    Dim ex As SqlException
    If e.Status = UpdateStatus.ErrorsOccurred Then
    ex = e.Errors
    If ex.Number = ERRPRIMARYKEY Then
    e.Status = UpdateStatus.Continue
    End If
    End If
    End Sub

    End Class

    End Namespace


  • Tableadapter error handling