我如何获得最后一个交易号码? [英] How do I get the last transaction number?

查看:84
本文介绍了我如何获得最后一个交易号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用自动编号的MS.Access表在我的VB.net应用程序中存储事务。



我在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。


< blockquote>谢谢,Balboos,但因为它们是相关的我需要包装它们。基本上我要问的是,无论如何确定ExecuteNonQuery是否已完成。它在ADO中使用不是问题。


I use a autonumbered MS.Access table to store transactions in my VB.net 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.


这篇关于我如何获得最后一个交易号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆