这是我的代码
Dim Cn1 As ADODB.Connection
Dim iSQLStr As String
Dim field_num As Integer
Set Cn1 = New ADODB.Connection
Cn1.ConnectionString = _
"Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"DefaultDir=" & "C:\path\"
Cn1.Open
iSQLStr = "Select * FROM " & "file.txt" ' & " ORDER BY " & txtField.Text
field_num = CInt(1) - 1
Set Rs1 = Cn1.Execute(iSQLStr)
lstResults.Clear
While Not Rs1.EOF
DoEvents
Rs1.Fields(field_num).Value = "qaz"
If IsNull(Rs1.Fields(field_num).Value) Then
lstResults.AddItem "<null>"
Else
lstResults.AddItem Rs1.Fields(field_num).Value
End If
Rs1.MoveNext
Wend
我得到的错误就在这一行
Rs1.Fields(field_num).Value = "qaz"
它说“当前记录集不支持更新”,代码中有什么问题?
答案 0 :(得分:0)
我不确定这是否对文本文件有效,但是对于SQL Server,您需要更改LockTypeEnum值设置以允许编辑,请参阅此link,默认为adLockReadOnly
根据此link,无法通过ADO编辑文本文件。