我用这个代码导入一个文本文件(.CSV),但是当这个文件是用UTF-8代码创建的时候,它不能成功。只有我保存为ANSI代码(使用Note.exe),就可以了。
Function getDataset(ByVal sql As String, ByVal path As String) As DataSet
'Try
'Dim connstr As String = GetINI("Setting", "cString", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\DataSouce\DataBase.mdb", Application.StartupPath & "\setting.ini")
Dim connstr As String = "Provider=Microsoft.jet.OLEDB.4.0;Data Source= " & path & "\;Extended Properties=""text;HDR=YES;FMT=Delimited"""
Dim conn As OleDbConnection = New OleDbConnection(connstr) '("provider=microsoft.Jet.OLEDB.4.0;data source=" & CurDir() & "\data.mdb")
Dim adapter1 As OleDb.OleDbDataAdapter = New OleDbDataAdapter(sql, conn)
Dim cmd As OleDbCommand = New OleDbCommand
Dim commandBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(adapter1)
getDataset = New DataSet
adapter1.Fill(getDataset, "temp")
'Catch ex As Exception
' MsgBox(ex.Message)
'End Try
End Function
我什至尝试像这样构建一个schema.ini,也不行
[temp.CSV]
Format=Delimited(,)
ColNameHeader=false
MaxScanRows=0
CharacterSet= ANSI
(or UTF-8 )