文本文件处理方式不同

时间:2015-07-10 19:15:20

标签: text-files ado

我正在尝试使用Ado Recordset从csv.txt文件中读取 尝试时我没有得到任何结果.. 当我将原始文件的内容复制到一个新的文本文件中,并从该文件中读取时,它可以正常工作。

任何想法可能是什么原因?

第二个文件的尺寸较小,约为1/2。这是我能看到的唯一区别。这让我很生气: - )

“修改 更新代码& SCHEMA.INI

代码:

Sub ImportTextFiles()
    Dim objAdoDbConnection As ADODB.Connection
    Dim objAdoDbRecordset As ADODB.Recordset
    Dim strAdodbConnection As String
    Dim pathSource As String
    Dim filename As String

    pathSource = "C:\Users\me\Desktop\Reports\"
    filename = "test1.txt"
    'filename = "test2.txt"

    strAdodbConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" _
                        & "Data Source=" & pathSource _
                        & ";Extended Properties=""text;HDR=yes;FMT=Delimited"";"

    Set objAdoDbConnection = CreateObject("Adodb.Connection")
    Set objAdoDbRecordset = CreateObject("ADODB.Recordset")
    With objAdoDbConnection
        .Open (strAdodbConnection)
        With objAdoDbRecordset
             .Open "Select top 10 * FROM " & filename & " WHERE [Date] > #01/01/2000# ", objAdoDbConnection, adOpenStatic, adLockOptimistic, adCmdText
            If Not objAdoDbRecordset.EOF Then objAdoDbRecordset.MoveFirst
                Do While Not objAdoDbRecordset.EOF
                    Debug.Print "Field(0): " & objAdoDbRecordset(0).Value
                    objAdoDbRecordset.MoveNext
            Loop
            .Close
        End With
        .Close
    End With

    Set objAdoDbRecordset = Nothing
    Set objAdoDbConnection = Nothing
End Sub

Schema.ini:
[Test1.txt]
col1=date text
col2=interval integer
col3=application text
[Test2.txt]
col1=date text
col2=interval integer
col3=application text

1 个答案:

答案 0 :(得分:0)

notepadd ++给了我答案,file1是ucs-2编码的,新创建的utf-8