M
Max
The question of how to import a text file into the database table has
been asked many times. The code that suits me was given by Paul
Clement is the following:
Sub ImportTextToAccessADO()
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sqlString As String
cnn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\DB1.mdb;" & _
"Jet OLEDB:Engine Type=4;"
sqlString = "SELECT * INTO [tblSample2] FROM
[Text;HDR=NO;DATABASE=e:\My
Documents\TextFiles].[Sample2.txt]"
cnn.Execute sqlString
cnn.Close
End Sub
It works great but only if the table doesn't exist. My questions are
how to do this if the following table already exists. Will bulk Insert
like this work or do I have to use adapter to fill a dataset and then
insert into the table row by row. Also how can I check if the table
exists then I delete it and create a new one but with the same schema
as it had before. Appying the above code to the table that doesn't
exist creates a new table with columns labelled F1, F2, etc. How do I
create custom columns?
I would greatly appreciate any input on this (preferably using .NET).
Thank you.
been asked many times. The code that suits me was given by Paul
Clement is the following:
Sub ImportTextToAccessADO()
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sqlString As String
cnn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\DB1.mdb;" & _
"Jet OLEDB:Engine Type=4;"
sqlString = "SELECT * INTO [tblSample2] FROM
[Text;HDR=NO;DATABASE=e:\My
Documents\TextFiles].[Sample2.txt]"
cnn.Execute sqlString
cnn.Close
End Sub
It works great but only if the table doesn't exist. My questions are
how to do this if the following table already exists. Will bulk Insert
like this work or do I have to use adapter to fill a dataset and then
insert into the table row by row. Also how can I check if the table
exists then I delete it and create a new one but with the same schema
as it had before. Appying the above code to the table that doesn't
exist creates a new table with columns labelled F1, F2, etc. How do I
create custom columns?
I would greatly appreciate any input on this (preferably using .NET).
Thank you.