Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

ADO 2.5 INSERT Statement (VB6)

  • 27-06-2003 04:03PM
    #1
    Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭


    Folks
    I'm running an insert statement into an Access database using ADO 2.5. What I want to know is can I return values if I use the Connection classes Execute statement. For example:

    I have a table, Jobs, consisting of these fields:

    JobID - AutoNum, primary key
    Description - Text
    JobDate - Date/Time

    and I want to do the following*
    sqlString = "INSERT INTO Jobs (Description, JobDate) " 
    sqlstring = SQLSTRING & "VALUES ('BLAH', SOMEDATE)"
    
    with objConnection
        .BeginTrans
        .Execute sqlString '// This is the bit I'm interested in
        .CommitTrans
    end with
    
    

    When I execute the insert statment is there anyway I can get the value of the WorkItemID field returned from the Execute method? At present it returns a closed recordset which is no use to me.

    I know I could use the AddNew method on a recordset to achieve these results, but I was just wondering.


    *Example code only, probably full of errors


Comments

  • Moderators, Home & Garden Moderators, Regional Midwest Moderators, Regional West Moderators Posts: 16,716 Mod ✭✭✭✭yop


    You are doing an INSERT so you will not get back values from the recordset.
    You have to do an explicit SELECT to get back the field


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    What I was looking for the the equivalent of Oracle's RETURNING clause. Can't find one, musn't be one.


  • Closed Accounts Posts: 94 ✭✭boo-boo


    Not with Access, at least not Access '97 for sure.

    You could include the select statement within the transaction,
    & then get the select (MAX) id (if the rows are auto incrementing)
    though, but this is a bit of a hack.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    I've no problems with a bit of a hack, I'll give it a go. Does anybody know if there is something like a RETURNING clause with MySQL? I'll look it up anyway but I'll be lazy for now ...


  • Closed Accounts Posts: 333 ✭✭McGintyMcGoo


    Why don't you create a recordset to return a set of data?


  • Advertisement
Advertisement