Reading csv file into access database

I want to read the csv file in the 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 message:

'C:\Documents and Settings\username\Desktop\test.csv'

not a valid path. Make sure that the path name is correct and that you are connected to the server on which the file is located.

It’s strange that there really is a file, so what else could go wrong?

+3
source share
1 answer

Nothing,

I found what I was doing wrong.

Instead of specifying the path to the file, I gave 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
+2
source

Source: https://habr.com/ru/post/1732831/


All Articles