SQLite.NET输出参数 [英] SQLite.NET output parameter
问题描述
我有一个对象,其中包含来自DB的数据.该对象具有一个ID,该ID在DB中是自动递增"字段.创建对象时,我不知道他的ID,直到我向DB中插入新记录.然后,我想找回ID字段的自动生成的值.我试图通过添加一个Output参数来做到这一点,但是当我尝试将 Direction
设置为 ParameterDirection.Output
时,SQLite.NET抛出了 NotSupportedException
.
我能做什么?除ID以外的其他字段不是唯一的.
另一种选择是在程序中手动自动递增,但是实现起来似乎有点复杂.非常感谢.
I have a object that contains data from a DB. The object has a ID, which in the DB is auto increment field. When creating an object i dont know his ID, until i insert a new record to the DB. Then i want to get back the auto generated value of ID field.
I tried to do so by adding a Output parameter, but SQLite.NET throws a NotSupportedException
when i try to set the Direction
to ParameterDirection.Output
.
What can i do? The other fields except ID are not unique.
A other option is to auto increment manually, in the program, but it seems to be a bit complicated to implement.
Thanks a lot.
推荐答案
SELECT last_insert_rowid();
这将获取最后插入的ROWID.如果表中的列的类型为INTEGER PRIMARY KEY,则该列是该行ID的另一个别名.
This will get the last inserted ROWID. If the table has a column of type INTEGER PRIMARY KEY then that column is another alias for the rowid.
这篇关于SQLite.NET输出参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!