I'm not up on oledb. I pretty much stick with ADO so my example uses that. You have to split the input line into fields. You do that with (what a coincidence) the Split method
Dim sr As New StreamReader("d:\temp\test.txt")
Dim con As New ADODB.Connection
Dim qry As String
con.Open("Driver={SQL Server};Server=.\SQLEXPRESS;Database=mydb;Trusted_Connection=yes;")
Do Until sr.EndOfStream
Dim line As String = sr.ReadLine
Dim cols() As String = line.Split("|")
qry = "INSERT INTO TestImport (Col1,Col2,Col3,Col4,Col5,Col6,Col7) Values(" & _
"'" & cols(0) & "'," & _
"'" & cols(1) & "'," & _
"'" & cols(2) & "'," & _
"'" & cols(3) & "'," & _
"'" & cols(4) & "'," & _
"'" & cols(5) & "'," & _
"'" & cols(6) & "')"
con.Execute(qry)
Loop
sr.Close()
con.Close()
"Split" allows you to specify the character that separates the fields. I took the liberty of assuming that all fields are varchar. You do not need the single quotes around numeric fields. Also, for this example, I don't use a parameterized query which leaves the app open to a SQL injection attack unless you trust, or have verified your input data.
Reverend Jim
Carpe per diem
3,600 posts since Aug 2010
Reputation Points: 561
Solved Threads: 447
Skill Endorsements: 32