Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cannot open *.CSV as ADO Recordset
Message
Information générale
Forum:
Visual Basic
Catégorie:
Bases de données DAO/RDO/ODBC/ADO
Divers
Thread ID:
00409913
Message ID:
00410586
Vues:
24
>>>I am using "Driver={Microsoft Text Driver (*.txt; *.csv)" to open CSV text files as ADO recordsets. It works fine but only if the files have TXT extensions. How can I get it to read files with CSV extensions?
>>
>>Have you tried specifying the file extension this way: filename#csv?
>>
>>If not working, please show your code.
>
>Do you mean replacing the period in the file name with pound? Does not work. Here is the code:

Use this:
Option Explicit

Private oFileConn As ADODB.Connection
Private oRS As ADODB.Recordset

Private Function GetFileRS() As Recordset
Dim msPath As String
Dim msFile As String
Dim msLine As String
Dim i As Long

    msPath = "c:\temp\"
    msFile = "[test.csv]"
    Set oFileConn = New Connection
    With oFileConn
        .Mode = adModeReadWrite
        .CursorLocation = adUseClient
        .Open "Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=" & _
              msPath & ";DefaultDir=" & msPath & ";Uid=;Pwd=;"
    End With
    Set oRS = New Recordset
    oRS.Open "select * from " & msFile, oFileConn
    oRS.ActiveConnection = Nothing
    Set GetFileRS = oRS
End Function

Private Sub Command1_Click()
    Set DataGrid1.DataSource = GetFileRS
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform