Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB6, ADO, Oracle and Identities

Posted on 2006-11-15
4
Medium Priority
?
552 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

688 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