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.Fill(Me.DataSet11.tblContact)
For Each objItem2 In colItems
myNewRow = Me.DataSet11.tblContact.NewRow
'get the company name
If IsNothing(objItem2.CompanyName) Then
myNewRow("Company") = ""
Else
myNewRow("Company") = NullStrCheck(objItem2.CompanyName.ToString)
End If
'get the firstname
If IsNothing(objItem2.FirstName) Then
myNewRow("FirstName") = ""
Else
myNewRow("FirstName") = NullStrCheck(objItem2.FirstName.ToString)
End If
'get the last name
If IsNothing(objItem2.LastName) Then
myNewRow("LastName") = ""
Else
myNewRow("LastName") = NullStrCheck(objItem2.LastName.ToString)
End If
'get the phone number
If IsNothing(objItem2.CompanyMainTelephoneNumber) Then
myNewRow("PhoneNo") = ""
Else
myNewRow("PhoneNo") =
NullStrCheck(objItem2.CompanyMainTelephoneNumber.T oString)
End If
'get the faxno
If IsNothing(objItem2.BusinessFaxNumber) Then
myNewRow("FaxNo") = ""
Else
myNewRow("FaxNo") = NullStrCheck(objItem2.BusinessFaxNumber.ToString)
End If
'get the email
If IsNothing(objItem2.Email1Address) Then
myNewRow("EmailAddress") = ""
Else
myNewRow("EmailAddress") = NullStrCheck(objItem2.Email1Address.ToString)
End If
'add record
Try
Me.DataSet11.tblContact.Rows.Add(myNewRow)
Catch ex As Exception
MessageBox.Show(Err.Number & " - " & Err.Description & " - " & Err.Source)
GoTo NextRecord
End Try
myCurrentRow = myCurrentRow + 1
System.Windows.Forms.Application.DoEvents()
Me.lblImportStatus.Text = "Importing Record " & myCurrentRow & " of " &
myCount & " records."
NextRecord:
Next
Me.lblImportStatus.Text = "Saving Information into Program"
System.Windows.Forms.Application.DoEvents()
'update the dataset
Me.daContact.Update(Me.DataSet11.tblContact)
"Fergus Cooney" <fi****@post.com> wrote in message
news:u5**************@TK2MSFTNGP09.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,
NullReferenceException, 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