我使用自动编号的MS.Access表在我的VB应用程序中存储事务。 我在Begin / Commit / Rollback循环中插入数据。 在我使用
插入记录后进行一系列转换Dim pCmd As New OleDb.OleDbCommand(sQ,oCn,oTr) pCmd.ExecuteNonQuery()我需要得到第一个事务的自动编号,用它作为下一个子事务的指针。 但是在事务表上使用Max(Id)无法正常工作因为我无法确定ExecuteNonQuery是否完整? 有没有办法确定表格是否已更新? 希望这很有意义。 Meenog 我尝试过: ExecuteNonQuery返回更新的行数但立即查询表的Max(Id) urns前一个行号。
解决方案进一步挖掘www之后我发现解决方案如下: Dim pCmd As New OleDb.OleDbCommand(sQ,oCn,oTr) pCmd.ExecuteNonQuery() pCmd.CommandText =SELECT @@ Identity parent = CInt(pCmd.ExecuteScalar) 其中parent是插入行的自动编号ID。
谢谢,Balboos,但因为它们是相关的我需要包装它们。基本上我要问的是,无论如何确定ExecuteNonQuery是否已完成。它在ADO中使用不是问题。
I use a autonumbered MS.Access table to store transactions in my VB application. I insert data within a Begin/Commit/Rollback loop. Doing a series of tranactions, after I insert a record by using
Dim pCmd As New OleDb.OleDbCommand(sQ, oCn, oTr) pCmd.ExecuteNonQuery()I need to get the autonumber of the first transaction to use it as a pointer for the next few child transactions. However using Max(Id) on the Transaction Table does not work always correctly as I cannot determine if ExecuteNonQuery is complete? Is there any way to determine that the table is updated? Hope that makes sense. Meenog What I have tried: ExecuteNonQuery returns the number of rows updated but immediately querying Max(Id) of the table usually returns the immediately previous row number.
解决方案 After further mining of the www I found the solution as follows: Dim pCmd As New OleDb.OleDbCommand(sQ, oCn, oTr) pCmd.ExecuteNonQuery() pCmd.CommandText = "SELECT @@Identity" parent = CInt(pCmd.ExecuteScalar) where parent is the Autonumber Id of the Inserted Row.Thanks, Balboos, but because they are related I need to wrap them. Basically what I'm asking is is there anyway to determine if the ExecuteNonQuery is completed. It used not be a problem in ADO.更多推荐
我如何获得最后一个交易号码?
发布评论