在SQL Server CE中插入行并检索新行的标识 [英] Inserting a row and retrieving identity of new row in SQL Server CE
问题描述
我正在尝试插入一行,并使用类似以下内容来获取新行的标识:
I'm trying to insert a row and get back the new row's identity with something like this:
INSERT INTO blah....;
SELECT @@IDENTITY as NewID;
我正在尝试通过C#中的DbCommand对象的一次调用来执行这两个语句...这似乎不起作用,或者我出了点问题.
I'm trying to execute both statements with a single invocation of a DbCommand object in C#... it doesn't seem work or I've got something wrong.
我读到Compact Edition不支持批量执行多个语句...但是我也发现了这一点:
I've read that Compact Edition doesn't support executing multiple statements in a batch... but I also found this:
如果要同时运行多个查询,则必须为每个语句添加换行符,并在每个语句末尾添加分号.
If you want to run multiple queries simultaneously, you must include a new line character for each statement and a semicolon at the end of each statement.
来源: http://technet.microsoft.com/en-us/library/bb896140(SQL.110).aspx
那它行不通吗?如果是的话,我还缺少什么?
So does it work or not... and if so what am I missing?
(我意识到我可以执行两个命令,并且效果很好,但是我想知道是否丢失了某些东西).
(I realise I can execute two commands and that works fine, but I wonder if I'm missing something).
推荐答案
这看起来像是文档错误,反之亦然.每个ExecuteNonQuery调用只能执行一条语句.
That looks like a doc error, it is the other way around. You can only execute a single statement per ExecuteNonQuery call.
这篇关于在SQL Server CE中插入行并检索新行的标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!