|
楼主 |
发表于 2010-12-20 14:44
|
显示全部楼层
我用以下的代码想要读取csv文件,但是读不到内容。
原文件是用“tab”分开的,如果读用“,”分开的文件似乎就没有问题。请问怎么办?
Option Compare Database
Public Conn As New ADODB.Connection 'ADO
Public RS As New ADODB.Recordset
Public Rs1 As New ADODB.Recordset
Public Function ReadCSVFile(ByVal strFilePath As String, ByVal strFileName
As String)
Dim i As Integer
Conn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"DBQ=" & strFilePath & ";Extensions=tab,asc,csv,txt;Persist
Security Info=False"
With RS
.CursorType = 2
.LockType = 3
.CursorLocation = 3
.ActiveConnection = Conn
End With
Set Conn = CurrentProject.Connection
sqlcsv = "SELECT * FROM [" & strFileName & "]"
RS.Open sqlcsv
RS.Move (0)
SQL = "Select * From table_Ringo"
Rs1.Open SQL, Conn, 1, 3
Do Until RS.EOF
Rs1.AddNew
For i = 0 To RS.Fields.Count - 1
Rs1(i) = RS(i)
Next
RS.MoveNext
Loop
Rs1.UpdateBatch
Rs1.Close
Set Rs1 = Nothing
RS.Close
Set RS = Nothing
Conn.Close
Set Conn = Nothing
End Function |
|