开发者

reading csv file into access database

开发者 https://www.devze.com 2022-12-20 00:33 出处:网络
I want to read a csv file into anaccess database , here is my code : Private Sub load_csv() Dim ConnectionString As String

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
0

精彩评论

暂无评论...
验证码 换一张
取 消