Hi all,

I use VB6/ADO 2.5 to write middle tier dlls for front tiers. One function is to create new record in Oracle and return the newly created primary key to the front end. The primary keys is automatically generated by Oracle triggers when cn.Execute or rs.UpdateBatch runs.

My question is: How can I get the newly generated key without re-open the recordset again? Right now I have to re-open the recordset in order to get the primary key, but I am afraid that last record might not be the one I have just created.

Any help would be very appreciated. My code is like this:


cn.Open
rs.ActiveConnection = cn

' retrive fields including primary key field order by primary key field
rs.Open strSQL

rs.AddNew

' some code to assign values to rs, except the primary key

rs.UpdateBatch

' open again to get the newly generated primary key
rs.Open strSQL
rs.MoveLast

cn.CommitTrans