DAO 到 .mdb、ADO 到 .mdf 比较
此代码基于连接表编辑记录集,适用于 DAO/.mdb 数据库。
RS.Edit
RS.fields("fieldA").value = 0 'in table A
RS.fields("fieldB").value = 0 ' in table B
RS.Update
该代码已在 sql server 数据库上转换为 ado,但失败并显示错误消息:
运行时错误“-2147467259”(80004005)': 无法从多个表插入或更新列。
但是,如果像这样进行更改,它似乎可以工作:
RS.fields("fieldA").value = 0 'in table A
RS.Update
RS.fields("fieldB").value = 0 ' in table B
RS.Update
这是使用 sql server 执行操作的正常方法还是有问题。 我问这个问题是因为在尝试找到解决方案时(在放入额外的更新语句之前),我将记录集类型更改为批量乐观,并且没有收到错误消息,但只编辑了一个表的记录。
This code editing a recordset based on joined tables works in DAO/.mdb database
RS.Edit
RS.fields("fieldA").value = 0 'in table A
RS.fields("fieldB").value = 0 ' in table B
RS.Update
The code was converted to ado on a sql server database and it failed with an error message:
Run-time error '-2147467259' (80004005)' :
Cannot insert or update columns from multiple tables.
However it appears to work if it is altered like so :
RS.fields("fieldA").value = 0 'in table A
RS.Update
RS.fields("fieldB").value = 0 ' in table B
RS.Update
Is this a normal way to do things with sql server or is there a gotcha to it.
I ask because when trying to find a solution (before I put in the extra update statement) I changed the recordset type to batchoptimistic and I got no error messge but only one table's record was edited.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然,记录集的数据源是从多个表返回数据的 SQL。是的,一次只能更新一张表是正常的。如果您想在单个原子步骤中更新多个表中的值(以便其他客户端无法读取“中间值”,其中一个表已更改,但另一个表未更改),则需要 使用事务。
Apparently, the data source of your recordset is an SQL returning data from multiple tables. Yes, it's normal that you can only update one table at a time. If you want to update values from multiple tables in a single, atomic step (so that no other client use can read the "intermediate value", where one table is changed but the other is not), you need to use a transaction.