Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: How to get the ID of a newly added record from ADO

Re: How to get the ID of a newly added record from ADO

From: tojo <Tojo_at_hotmail.com>
Date: Tue, 19 Apr 2005 13:47:26 +0200
Message-ID: <MPG.1ccf0e3c6d02a8cd98970a@news.t-online.de>


In article
<9fcb29531f54af4f130aab7eee04f10b_at_localhost.talkaboutdatabases.com>, mattwoberts_at_yahoo.com says...
> Hi,
> I have seen previous posts about this, and various solutions, but none of
> them are working for me. I am trying to get Oracle to auto-return the ID
> of the new record I added, via ADO. I know its possiblle, but its not
> working for me.
>
> I am using the latest Oracle ODBC driver, and Oracle 9iRel2. My code,
> which I am sure *should* work, is:
>
> mConn.ConnectionString = "Driver={Oracle in
> OraHome92};uid=Envoy;pwd=significance;dbq=EnvoyOne;"
>
> mConn.CursorLocation = adUseServer
> mConn.Open
>
> rs.Open "select * from test where id < -1", mConn, adOpenKeyset,
> adLockOptimistic
> rs.AddNew "name", "newname"
> rs.Update
>
> MsgBox rs("id")
>
> -----
>
> The keys here is that the cursor location must be set to server, and the
> recordset opened "adOpenKeyset". I have a sequence and a trigger on the
> "test" table so that the ID is auto-generated. But...All I get is a null
> from the ID column after calling the update method.
>
>
>
> Any ideas?
>
>

Sorry I couldn't dig up any sample code, but I would go at like this (from memory):

cmd = new Command("INSERT INTO test (...) RETURNING id INTO &id, mConn); cmd.Parameters.Add("id", Int32, DirectionOutput) mConn.Open
cmd.Execute
Msgbox cmd.Parameters(0).Value ' this has the new id

(Close everything)

... something like that. Just stick to using Commands, Parameters and straight SQL, and you'll never go back to .AddNew/.Update

Received on Tue Apr 19 2005 - 06:47:26 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US