tags:

views:

18

answers:

1

Hi!

How do I get id of an insert query? Simple:

insert into Ex(sth) values("value");
select @@identity

does not work. When I try to ExecuteScalar or any other I get exception: {"There was an error parsing the query. [ Token line number = 3,Token line offset = 95,Token in error = select ]"}.

I remind this is the CE edition. I'm using MSVS2010

Thanks for your help.

A: 

The .Net SQL CE client does not support multiple statements.
You need to use two separate SqlCeCommands.

SLaks
well... but you cannot do it in separated queries while you get null from the Select. Are there any other solutions to the problem? I mean - getting id previously inserted row.
SOReader
I'm not sure. You could use a GUID (from the client) instead.
SLaks
Ok, got it but still smth is remaining :/ TableAdapter automaticaly closes its connection after query, so quering for @@identity doesn't make any sense - the query has to be made on the same connection - that's what I made. Unfortunately you lose the benefits of the visual editor, while you have to write additional function by your own ;(
SOReader