在TableAdapter.Insert SQl命令文本中使用SCOPE_IDENTITY [英] Use SCOPE_IDENTITY in TableAdapter.Insert SQl command text
本文介绍了在TableAdapter.Insert SQl命令文本中使用SCOPE_IDENTITY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hello dear programmers
As you know each TableAdapter has Insert command which is valued by SQL. but how can I get the inserted row ID by using SCOPE_IDENTITY in SQL command. I tried to that but VS show syntax error.
my database is MS Access.
Which syntax is correct? I found many on the web but non of them worked.
thank you
推荐答案
据我所知Access不支持批处理命令(这将是最简单的解决方案)所以最简单的方法是在插入数据并选择新插入的标识后立即执行新的select语句。
例如,看看 http://blogs.msdn.com/b/spike /archive/2009/12/02/getting-autonumber-from-access-via-select-identity-needs-to-be-done-in-same-connection-as-the-insert.aspx [< a href =http://blogs.msdn.com/b/spike/archive/2009/12/02/getting-autonumber-from-access-via-select-identity-needs-to-be-done-in- same-connection-as-insert.aspxtarget =_ blanktitle =New Window> ^ ]
As far as I know Access does not support batch commands (which would be the easiest solution) so probably the simplest way is to execute a new select statement right after inserting the data and selecting the newly inserted identity.
For example, have a look at http://blogs.msdn.com/b/spike/archive/2009/12/02/getting-autonumber-from-access-via-select-identity-needs-to-be-done-in-same-connection-as-the-insert.aspx[^]
这篇关于在TableAdapter.Insert SQl命令文本中使用SCOPE_IDENTITY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文