如何读取txt文件内容,一行一行的读取,读取一行后添加到数据库,再读取下一行,可以实现吗
------解决方案--------------------
sConn = "Server=127.0.0.1;Database=db;User Id=xxx;Password=xxx;"
Set conn = CreateObject("ADODB.Connection")
conn.Open sConn
Set rs = CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.Open "SELECT xx FROM tbl WHERE 1=0", 1, 4
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFile = oFS.OpenTextFile("c:\xxx\xxx.txt", 1, False)
Do While Not oFile.AtEndOfStream
sLine = oFile.ReadLine()
rs.AddNew
rs("xx") = sLine
Loop
oFile.Close
Set oFile = Nothing
Set oFS = Nothing
rs.UpdateBatch
If rs.State<>0 Then rs.Close
conn.Close
Set conn = Nothing
------解决方案--------------------
利用FSO的ReadLine() 这个是读取一行的
------解决方案--------------------
sConn = "Server=127.0.0.1;Database=db;User Id=xxx;Password=xxx;"
Set conn = CreateObject("ADODB.Connection")
conn.Open sConn
Set rs = CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.Open "SELECT xx FROM tbl WHERE 1=0", 1, 4
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFile = oFS.OpenTextFile("c:\xxx\xxx.txt", 1, False)
Do While Not oFile.AtEndOfStream
sLine = oFile.ReadLine()
rs.AddNew
rs("xx") = sLine
Loop
oFile.Close
Set oFile = Nothing
Set oFS = Nothing
rs.UpdateBatch
If rs.State<>0 Then rs.Close
conn.Close
Set conn = Nothing
------解决方案--------------------
楼主。。⊙╊⊙b汗。。。。。