0

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

我有一个程序可以保存一个包含 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()

这是被调用的 Sub。

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 命令。

4

0 回答 0