问题描述
我是原型使用ASP.NET MVC和SQL精简版在VS2008的应用程序。我已与对方很多一对多的关系,2实体。当我保存对象到数据库中,通过手工制作的SQL我需要找出他们的ID是这样我就可以放下一个记录到映射表中的两个实体之间。 AUTO_INCREMENT的ID字段其实这些表的唯一唯一标识符。我已经做了我的插入操作后,我该如何重新加载的记录,并抓住新分配的ID?
I am prototyping an app using ASP.NET MVC and SQL Compact Edition on VS2008. I have 2 entities that have have a many-to-many relationship with each other. When I save objects to the database through hand-crafted SQL I need to find out what their ID is so I can drop a record into the mapping table between the two entities. The auto_increment ID field is in fact the only unique identifier for the tables. So after I've done my insert, how do I re-load the record and grab the newly assigned ID?
RE:code-是艺术,我现在用的是内置的SqlCeConnection,从.NET 3.5库SqlCeCommand和SqlCeDataReader对象
RE: Code-is-art, I am using the builtin SqlCeConnection, SqlCeCommand, and SqlCeDataReader objects from the .NET 3.5 library.
推荐答案
使用SELECT @@ IDENTITY在随后的调用数据库。
Use "SELECT @@IDENTITY" in a subsequent call to the database.
紧凑型为单用户访问你不必担心交易等,以防止其他插件。
Compact is single user access you don't need to worry about transactions etc to protect against other inserts.
这篇关于获取AUTO_INCREMENT ID从SQL精简版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!