Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading csv file into access database

Tags:

vb.net

oledb

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 sure 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 ?

like image 483
Iulian Avatar asked Jun 10 '26 03:06

Iulian


1 Answers

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
like image 141
Iulian Avatar answered Jun 16 '26 14:06

Iulian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!