本文介绍了ADO VBNET更新/添加新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在将VBNet程序从DAO迁移到ADO。数据库是* .mdb数据库。 在DAO中,我执行了以下操作:打开数据库,使用SQL select命令创建记录集。然后我可以使用recordset.edit / .update或.addnew命令进行更新。 在ADO中,我执行以下操作: Public conn3 As New ADODB.Connection Dim rstGyles As ADODB.Recordset gsCurrentFilePath = OpenFileDialog1.FileName conn3 .Provider = Microsoft.Jet.OLEDB.4.0 conn3.Open(gsCurrentFilePath) rstGyles = conn3.Execute( SELECT * FROM bzGyle ORDER BY gNo DESC) 这对于阅读文件和显示数据非常有效,但不允许我使用以下内容进行更新: rstGyles.Edit,.Update 或 .Addnew 记录集似乎成为创造者在只读模式下编辑。 我知道答案可能是转移到SQL插入和更新命令,但我宁愿首先排除任何明显的错误。 我尝试了什么: 我尝试过使用 ' rstGyles.Open(SELECT * FROM bzGyle ORDER BY gNo DESC,conn3 ,, ADODB。 LockTypeEnum.adLockOptimistic) 这给了我错误91'对象引用未设置为对象的实例'。 我也尝试先运行,因为微软文件说在打开记录集之前必须设置锁定: rstGyles.LockType = ADODB。 LockTypeEnum.adLockOptimistic ' 在v3.0.4中尝试 但这会产生相同的信息。解决方案 我和其他人一起建议咬那个子弹并更新到ADO.NET - 特别是因为你已经花了很多时间试图克服使用过时技术造成的问题。 然而,尝试以下操作,看看它是否让你超过你的驼峰.. 1.我很确定这是产生错误的Lock类型,而不是 ADODB.LockTypeEnum.adLockOptimistic ,尝试 rstGyles.LockType = adLockOptimistic 或者尝试输入 ADODB.LockType 。并查看intellisense的内容或使用 rstGyles.Open(SELECT * FROM bzGyle ORDER BY gNo DESC,conn3)并确认错误消失。 2.尝试明确引用游标类型为 adOpenDynamic 而不是默认 I am migrating a VBNet programme from DAO to ADO. The database is an *.mdb database.In DAO I performed the following: Opened the database, created a recordset by using an SQL select command. I then could update using a recordset.edit/.update or a .addnew command.In ADO I do the folloing:Public conn3 As New ADODB.ConnectionDim rstGyles As ADODB.RecordsetgsCurrentFilePath = OpenFileDialog1.FileNameconn3.Provider = "Microsoft.Jet.OLEDB.4.0"conn3.Open(gsCurrentFilePath)rstGyles = conn3.Execute("SELECT * FROM bzGyle ORDER BY gNo DESC") This works perfectly for reading the file and displaying data but doesn't allow me to update using:rstGyles.Edit, .Update or .Addnew The recordset seems to be being created in read only mode.I know the answer may be to move to SQL insert and update commands but I'd prefer to rule out any obvious mistake first.What I have tried:I have tried using 'rstGyles.Open("SELECT * FROM bzGyle ORDER BY gNo DESC", conn3,, ADODB.LockTypeEnum.adLockOptimistic) This gives me error 91 'object reference not set to an instance of an object'.I've also tried running first because microsoft documents say the lock must be set before opening a recordset:rstGyles.LockType = ADODB.LockTypeEnum.adLockOptimistic 'tried in v3.0.4but this comes up with the same message. 解决方案 I'm with the others who are suggesting biting that bullet and updating to ADO.NET - especially as you are already spending ages trying to overcome the problems caused by using out-of-date technology.However, try the following to see if it gets you over your hump..1. I'm pretty sure it's the Lock type that is generating the error so, instead of ADODB.LockTypeEnum.adLockOptimistic, try rstGyles.LockType = adLockOptimisticAlternatively try putting ADODB.LockType. and see what comes up with intellisense OR using rstGyles.Open("SELECT * FROM bzGyle ORDER BY gNo DESC", conn3) and confirm that the error goes away.2. Try explicitly quoting the cursor type as adOpenDynamic rather than the default 这篇关于ADO VBNET更新/添加新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 11:43