Hi
I am importing alot of data from a text file into an access database with the code below. (Comma delimited)
The problem is that I do not want to import duplicate records. I have the "IDNr" column in my access database set to "not allow duplicates" and need my code to check if there is already a record in the database before trying to import the data. Otherwise it will just give me an error and not import the rest of the data.
Any idea what I could do? Would appreciate some help
Thanks
I am importing alot of data from a text file into an access database with the code below. (Comma delimited)
The problem is that I do not want to import duplicate records. I have the "IDNr" column in my access database set to "not allow duplicates" and need my code to check if there is already a record in the database before trying to import the data. Otherwise it will just give me an error and not import the rest of the data.
Any idea what I could do? Would appreciate some help
Thanks
VB.NET:
Public Sub UPdateDB()
Dim ImportDBFileExists As String = "C:\test\outputfile1.txt"
If System.IO.File.Exists(ImportDBFileExists) = True Then
'Database Import
Dim cnn As New ADODB.Connection
Dim Rec As New ADODB.Recordset
Dim sqlString As String
cnn.Open( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\test\test.mdb;" & _
"Jet OLEDB:Engine Type=4;")
sqlString = "INSERT INTO [Sheet1] (SwipeCard, FirstName, LastName, Faculty, Degree, IDNr, EndDate, [e-mail]) SELECT SwipeCard, FirstName, LastName, Faculty, Degree, IDNr, EndDate, [e-mail] FROM [Text;DATABASE=C:\test;].[outputfile1.txt]"
cnn.Execute(sqlString)
Else
Return
End If
End Sub