Friday, March 9, 2012

getting newly created id number(asap)

hello,

i have a problem in my sql. im using a stored procedure and i want to get the newly created id number to be used to insert in the other table.

it works like:

insert into table() values()

select @.id = (newly created id number) from table

insert into table1() values(@.id)

something like that.

Hi lenerd,

You should usescope_identity for this!

Here are some links, please give it a look and try!

http://msdn2.microsoft.com/en-us/library/ms190315.aspx
|||

Hi lenerd3000

its too easy, i hope you know what command object is. execute scalar will return the primary key of newly generated record.

dim myID as integer =CType(myCommand.ExecuteScalar(),Integer)

hope it helps

No comments:

Post a Comment