我如何获得最后一个交易号码?

编程入门 行业动态 更新时间:2024-10-08 10:49:30
本文介绍了我如何获得最后一个交易号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用自动编号的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.

更多推荐

我如何获得最后一个交易号码?

本文发布于:2023-11-13 03:03:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583246.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何获得   号码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!