Solved

VB6, ADO, Oracle and Identities

Posted on 2006-11-15
4
496 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

762 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

18 Experts available now in Live!

Get 1:1 Help Now