Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当对表执行 SQLDataAdapater.Update 时,您将如何检索每一行的 @@IDENTITY 值?
例如。是否可以修改/拦截由 SQLCommandBuilder 生成的 InsertCommand,例如添加一个输出参数,然后在 da.RowUpdated 事件中检索其值???
比尔·沃恩对此略知一二。他们的关键是调整您的 InsertCommand。
请参阅“管理@@IDENTITY 危机”。
注意:实际的解决方案使用 SCOPE_IDENTITY() 以保证触发安全。
这是一篇被证明非常有用的文章,其中解释了“调整 InsertCommand”的技巧,以及将查询设置为“Scalar”的技巧
MSDN 文章(在 VB.Net 中)
再见!
彼得