reading csv file into access database
I want to read a csv file into an access database , here is my code :
Private Sub load_csv()
Dim ConnectionString As String
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & input_file & ";" & _
"Extended Properties=""Text;HDR=Yes"""
Dim TextConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
TextConnection.Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter _
("SELECT * INTO [MS Access;Database=" & current_db & "].[Rapoarte] FROM [" & input_file & "]", TextConnection)
End Sub
When i run it i get an error :
'C:\Documents and Settings\username\Desktop\test.csv'
is not a valid path. Make s开发者_开发技巧ure that the path name is spelled correctly and that you are connected to the server on which the file resides.
The strange thing is that the file really is there, so what else could go wrong ?
Never mind,
I found what I was doing wrong.
Instead of providing the file path i was giving it the file name. For reference it should look like this.
Private Sub load_csv()
Dim ConnectionString As String
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & file_path & ";" & _
"Extended Properties=""Text;HDR=Yes"""
Dim TextConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
TextConnection.Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter _
("SELECT * INTO [MS Access;Database=" & current_db & "].[Rapoarte] FROM [" & input_file & "]", TextConnection)
End Sub
精彩评论