如何更新记录集

发布于 2024-12-29 11:01:52 字数 811 浏览 1 评论 0原文

这是我的代码

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"

它说“当前记录集不支持更新”,代码中有什么问题?

here is my code

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

The error i get is in this line

Rs1.Fields(field_num).Value = "qaz"

it says "The current recordset does not support updating", what is wrong in the code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饭团 2025-01-05 11:01:52

我不确定这对于文本文件是否有效,但对于 SQL Server,您需要更改 LockTypeEnum 值设置以允许编辑,请参阅此 链接,默认为adLockReadOnly

编辑

根据此 链接 无法通过 ADO 编辑文本文件。

I'm not sure if this is valid for text files but with SQL Server you need to change the LockTypeEnum Value setting to allow editing see this link, the default is adLockReadOnly

Edit

According to this link it is not possible to edit a text file via ADO.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文