I'm having a simple problem but cant find a solution:
I'm creating a row in my table client, but I don't know how recovery the id of the table that I just created, for example:
ALTER proc [dbo].[spinsert_client]
@idclient int output,
@name varchar(20),
@surname varchar(40),
as
insert into client(name,surname)
values (@name,@surname)
here I insert a client, now I want recovery that exact same idclient to insert "products" with it without have to manually search this client , I tried recovering the last row of the client table but I realise that if more than one person is using the same database in different computers it can be a problem, so I need create a client and recovery his id at the same time (it is an assumption I don't know). Im using sql server and Visual studio with c#
sorry for my bad English and thanks for the attention
edit------------------- solution:
ALTER proc [dbo].[spinsert_client]
@idclient int output,
@name varchar(20),
@surname varchar(40)
as
insert into client(name,surname)
values (@name,@surname)
Select @@IDENTITY as newId;
them in my c# code:
rpta= SqlCmd.ExecuteScalar().ToString();