load txt file into Access database

rrrprogrammer

Member
Joined
Aug 15, 2008
Messages
7
Programming Experience
10+
Using VB.NET, If i need to read a txt file that has 2 million records and they need to be added to Access database. Before I add these records, I have to check if the record exists in the table. If the record exist, then update the record, else add a new record

How do i go about it? Will I be using ADO or DAO to load into Access database? Are there any sample code out there ?
Also, since the table will be huge, does the table needed to be indexed?
 
Here is an example of how you can add records to your database from a text file.

VB.NET:
Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
        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:\logs\import\Test.mdb;" & _
        "Jet OLEDB:Engine Type=4;")
        sqlString = "INSERT INTO [Sheet1] (FirstName, LastName, [e-mail]) SELECT FirstName, LastName, [e-mail] FROM [Text;DATABASE=C:\logs\import;].[outputfile1.txt]"
        cnn.Execute(sqlString)

Just add an If statement to check if the data exists or configure your access columns to not allow any duplicates. Hope this helps.
 
Back
Top