The problem is that there are 2 identical records that are trying to be
added... so on this error, i would like to just ignore the add of the second
record and cycle to the next.
Thanks for everyone's help!
Full Code:
Dim myNewRow As DataRow
Me.daContact.Fi ll(Me.DataSet11 .tblContact)
For Each objItem2 In colItems
myNewRow = Me.DataSet11.tb lContact.NewRow
'get the company name
If IsNothing(objIt em2.CompanyName ) Then
myNewRow("Compa ny") = ""
Else
myNewRow("Compa ny") = NullStrCheck(ob jItem2.CompanyN ame.ToString)
End If
'get the firstname
If IsNothing(objIt em2.FirstName) Then
myNewRow("First Name") = ""
Else
myNewRow("First Name") = NullStrCheck(ob jItem2.FirstNam e.ToString)
End If
'get the last name
If IsNothing(objIt em2.LastName) Then
myNewRow("LastN ame") = ""
Else
myNewRow("LastN ame") = NullStrCheck(ob jItem2.LastName .ToString)
End If
'get the phone number
If IsNothing(objIt em2.CompanyMain TelephoneNumber ) Then
myNewRow("Phone No") = ""
Else
myNewRow("Phone No") =
NullStrCheck(ob jItem2.CompanyM ainTelephoneNum ber.ToString)
End If
'get the faxno
If IsNothing(objIt em2.BusinessFax Number) Then
myNewRow("FaxNo ") = ""
Else
myNewRow("FaxNo ") = NullStrCheck(ob jItem2.Business FaxNumber.ToStr ing)
End If
'get the email
If IsNothing(objIt em2.Email1Addre ss) Then
myNewRow("Email Address") = ""
Else
myNewRow("Email Address") = NullStrCheck(ob jItem2.Email1Ad dress.ToString)
End If
'add record
Try
Me.DataSet11.tb lContact.Rows.A dd(myNewRow)
Catch ex As Exception
MessageBox.Show (Err.Number & " - " & Err.Description & " - " & Err.Source)
GoTo NextRecord
End Try
myCurrentRow = myCurrentRow + 1
System.Windows. Forms.Applicati on.DoEvents()
Me.lblImportSta tus.Text = "Importing Record " & myCurrentRow & " of " &
myCount & " records."
NextRecord:
Next
Me.lblImportSta tus.Text = "Saving Information into Program"
System.Windows. Forms.Applicati on.DoEvents()
'update the dataset
Me.daContact.Up date(Me.DataSet 11.tblContact)
"Fergus Cooney" <fi****@post.co m> wrote in message
news:u5******** ******@TK2MSFTN GP09.phx.gbl...
Hi Chris,
A couple of thoughts..
When you trap Exceptions, it's usually good to be as specific as
possible. The Catch code may try an recover from the wrong error,
NullReferenceEx ception, for example.
If an Exception occurs, the current operation usually hasn't been
completed, so is that Remove necessary there?
It might help if you show the full loop that you're talking about.
Regards,
Fergus