Hello!
I have a vb6 application running with the following code to import a text file to an Access database. Can anyone tell me how to do the same import using ADO.NET?
I have a vb6 application running with the following code to import a text file to an Access database. Can anyone tell me how to do the same import using ADO.NET?
Code:
Private Sub import()
Dim strFileToOpen As String
Dim i As Long
Dim strLine As String
Dim varFields As Variant
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
strFileToOpen = "c:\test.txt"
con.ConnectionString = "c:\test.mdb"
con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.Open
rs.Open "SELECT * from tblMytable", con, adOpenStatic, adLockOptimistic
i = FreeFile
Open strFileToOpen For Input As #i
Line Input #i, strLine
Do While Not EOF(i)
Line Input #i, strLine
varFields = Split(strLine, ";")
With rs
.AddNew
!Field1 = varFields(0)
!Field2 = varFields(1)
!Field3 = varFields(2)
!Field4 = varFields(3)
!Field5 = varFields(4)
!Field6 = varFields(5)
!Field7 = varFields(6)
!Field8 = varFields(7)
!Field9 = varFields(8)
!Field10 = varFields(9)
!Field11 = varFields(10)
!Field12 = varFields(11)
!Field13 = varFields(12)
.Update
End With
Loop
Close #i
MsgBox "File was imported"
End Sub