Solved

VB6, ADO, Oracle and Identities

Posted on 2006-11-15
4
507 Views
Last Modified: 2013-12-25
I have a VB6 application that writes a record into an Oracle database.  The record's primary key is the employee id, which is an identity field.  However, after updating the record, I cannot retrieve the key in order to add subsequent child records.

VB6 using ADO 2.8
Connecting via an ODBC DSN that uses sqora32.dll (Oracle in OraHome92).
Transactions enabled.


Here's the code:

With rsEmp
    If bAdding Then
        .AddNew
    End If
    !namefirst = txtFname
    !namelast = txtLname
    lblEmpID.Caption = lCurrentEmp
    !hiredate = txtDateHired
    If IsDate(txtTermDate) Then
        !termdate = txtTermDate
    End If
    If chkSignature = 1 Then
        !issignonfile = "Y"
    Else
        !issignonfile = "N"
    End If
   
    If chkResume = 1 Then
        !iscv = "Y"
    Else
        !iscv = "N"
    End If
    If chkJobDesc = 1 Then
        !ISJOBDESC = "Y"
    Else
        !ISJOBDESC = "N"
    End If
    flexJobTitle.Row = 1
    !jobcode = sJobCode
    !empstatus = cmbStatus
    !emptype = cmbEmpType
    !reason = txtReason
    !Comments = txtComments & ""
    !Name = txtLname & ", " & txtFname
    .Update
    If bAdding Then
' crs working here - not getting the correct empid
        lCurrentEmp = !empid


At this point, lCurrentEmp is set to 0, as the empid field has not updated.  rsEmp was opened as:

    If OpenMode = READWRITE Then
        .CursorType = adOpenDynamic
        .LockType = adLockOptimistic
        .CursorLocation = adUseServer

Do I need to commit the transaction to get the record to update (the BeginTransaction was executed earlier in the code)?  If not, how do I get the value of the employee id after the new record is written?

Thanks in advance!




0
Comment
Question by:Clothahump
4 Comments
 
LVL 13

Expert Comment

by:newyuppie
ID: 17953773
i think you have to commit the transaction in order to get the record to update.
0
 
LVL 4

Author Comment

by:Clothahump
ID: 17956228
Okay.  I found the solution.  Requerying will force the update.

I change the code as follows:

    .Update
    If bAdding Then
' refresh the table to force the update.  The new record added should now be the first
' in the table since we are ordered by empid desc
        .Requery
        .MoveFirst
        lCurrentEmp = !empid

This does what I want it to.
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 18025201
PAQd, 500 points refunded.

DarthMod
CS Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now