Thanks.
int intNewID = Convert.ToInt32(command.ExecuteScalar());
I put select_scopeidentity() onto the end of my insert statement, ran the
above code and obtained my new ID. it runs in the same connection so the
ID
shouldnt belong to someone else's query, should it?
Deepak said:
Louise,
Use ExecuteScalar wchich returns the value of first column in the first
row,
and use the scope identity function to get the identity value you have
just
inserted. Below is some code to give you an idea.
create table #temp
( myid int identity,
n varchar(10)
)
insert into #temp
values('a')
select scope_identity() as [identity_value]
--
With Regards,
Deepak
[I code, therefore I am]
louise raisbeck said:
Hi, I do a sqlcommand.executenonquery on the click of a button, which
performs an insert statement. What is the most reliable way (i.e.
someone
else could insert at similar time) to get the id i have JUST created?