filesystem.copyfile之后的记录集错误0x80040e10

时间:2014-05-01 14:12:56

标签: vb.net filesystems recordset console.writeline file-copying

当我编码这种类型的编码时,我是初学者。请帮助我理解我从根本上做错了什么以及如何纠正它。

我有一个程序,它保存2个温度读数和压力读数的日志文件(文本文件)。我在一个记录集中打开了文件(这是第一次工作)所以我可以使用find运算符等等。我面临的问题是当我尝试存档较旧的读数时。我附上了代码片段:

最初使用此命令打开文件

rs.Open("SELECT Date, Pressure, Temp1, Temp2 FROM Env_Log_Overall.txt", connCSV, adOpenStatic, adLockOptimistic, adCmdText)

此代码段中出现错误。

Call purgeRecords(cleanRecords, rs) ' Copies all records from the archived record on to a temp file which gets renamed to be the original file

connCSV.Close()
connCSV.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\EnvironmentLogs\;Extended Properties='text;HDR=YES;FMT=Delimited'")
rs.Open("SELECT Date, Pressure, Temp1, Temp2 FROM Env_Log_Overall.txt", connCSV, adOpenStatic, adLockOptimistic, adCmdText) ' This is where the error is occurring
' Not sure if it is the way the file is being populated or the copyfile does something
rs.MoveFirst()

这是被调用的子。

Private Sub purgeRecords(cleanRecords As Integer, rs As ADODB.Recordset)
    Dim tempFileName As String = "C://EnvironmentLogs//Env_Log_Overall_temp.txt"
    Dim logFileName As String = "C://EnvironmentLogs//Env_Log_Overall.txt"


    rs.Move(cleanRecords)

    Dim tempFileLogs As Object = My.Computer.FileSystem.OpenTextFileWriter(tempFileName, False)
    tempFileLogs.WriteLine("Date, Pressure, Temp1, Temp2")

    Do
        tempFileLogs.WriteLine(rs(0).Value.ToString & ", " & rs(1).Value.ToString & ", " & rs(2).Value.ToString & ", " & rs(3).Value.ToString)
        rs.MoveNext()
    Loop While Not rs.EOF

    tempFileLogs.close()
    rs.Close()


    My.Computer.FileSystem.DeleteFile(logFileName)
    My.Computer.FileSystem.CopyFile(tempFileName, "C:\EnvironmentLogs\Env_Log_Overall.txt", True)


End Sub

我面临的问题是,在写入临时文件并将其复制之后,我无法将该文件作为带有SELECT字段的记录集打开。它只用SELECT *打开,我不能像以前那样执行SQL命令。

0 个答案:

没有答案