Hi Ann,
Below is an example of how to retrieve the new ID from a stored procedure:
Dim iNewID ' as Integer
Dim cmdInsert ' as ADODB.Command
Set cmdInsert = Server.CreateObject("ADODB.Command")
cmdInsert.ActiveConnection = sLocalConnectionStringOrConnectionObject '
Change this to your connection
cmdInsert.CommandType = adCmdStoredProc ' set the type to stored procedure
cmdInsert.CommandText = "spInsertUser" ' stored procedure spInsertUser,
change in your procedurename
cmdInsert.Parameters.Append (cmdInsert.CreateParameter("Return", adInteger,
adParamReturnValue))
cmdInsert.Parameters.Append (cmdInsert.CreateParameter("sUserLogin",
adWChar, adParamInput, 20, sUserLogin))
cmdInsert.Execute
iNewID = cmdInsert.Parameters(0) ' Return parameter (userID for the new
User)
First we create a ADO command object. Then we set the active connection. I
use a connection string here, but you could also use an explicitly created
connection.
Then we set the command type to adCmdStoredProc. This basically tells the
engine to expect a stored procedure. Then we tell it which stored procedure
to run.
When adding the parameters, I first create the output param
(adParamReturnValue) and then a second parameter which holds a user Login.
This parameter is just an example: change it to the parameters your stored
procedure expects.
Then we can execute the command object so we can retrieve the new ID from
the parameters collection by using:
iNewID = cmdInsert.Parameters(0)
HtH
Imar
At 07:02 AM 10/30/2000 -0800, you wrote:
>Hi,
> I have the same problems in ASP and any tips on that will be greatly
>appreciated. Thanks.
>-ann
>
>
>-----Original Message-----
>From: Imar Spaanjaars [mailto:Imar@S...]
>Sent: Friday, October 20, 2000 4:53 AM
>To: sql language
>Subject: [sql_language] Re: returning an auto value
>
>
>You can use the @@identity value. This will contain the ID of the last
>inserted record.
>Do something like this:
>
><SPROC>
>CREATE PROCEDURE spMySproc
> @ID int,
> @Description varchar(100)
>AS
> SET NOCOUNT ON
> INSERT INTO tblMyTable (ID, Description)
> VALUES (@ID, @Description)
> SET NOCOUNT OFF
> Return @@Identity
></sproc>
>
>This will return the last ID to the calling application
>
>If you need help to retrieve this return value in for instance
>ASP, let me
>know, and I'll give you some tips on that.
>
>HtH
>
>
>Imar
>
>
>
>At 03:21 PM 10/18/2000 +0100, you wrote:
> >Hi
> >
> >Hope someone can help with this.
> >
> >I'm writing a procedure that inserts a row in a table - what I
>want it to
> >do is get the auto increment number that it inserts and use
>this as data
> >for an insert in to another table
> >
> >How would I go about it ?
> >
> >thanks in advance
> >
> >Silk
> >
>
>