开发者

Return identity value from an insert in a generalized way in C#

I'd like to be able to get the identity value back after calling an insert statement. I can do this now and it works fine with SQL server by adding SET @RETURN_VALUE = SCOPE_IDENTITY() and using an out parameter.

The problem is that this would only work with SQL server and I need to support Oracle and SQLite as well. Now I know could write separate code for each but 开发者_C百科is there a generic way to do this in .NET?

Java for example has a getGeneratedKeys method which can be called after the insert, returning a result set of generated column names and values.

Any similar construct in .NET?

TIA


Unfortunately each DBMS has its own specific way of retrieving the last inserted identity value, so you have to write specific code for each DBMS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜