如何使用sqlbulkcopy获取primarkey值 [英] how to get primarkey value using sqlbulkcopy
本文介绍了如何使用sqlbulkcopy获取primarkey值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我正在使用sqlbulkcopy将数据块插入sql服务器数据库.是否有任何方法可以获取当前插入数据的主键值,以便可以将其插入日志表?
Hi
I am using sqlbulkcopy to insert chunks of data into sql server database.is there any way to get the primarykey value for recntly inserted data so that i can insert into log table?
推荐答案
在表中添加新列,即sessionid
之后,您可以通过sessionid选择ID.
IE.使用var sessionID = new GUID();
进行批量插入 SQL查询从TableName中选择ID,其中SessionID = sessionID;
我认为这会对您有所帮助.
Add a new column in the table i.e. sessionid
after that you can select the ids by the sessionid.
ie. Bulk Insert with var sessionID = new GUID();
SQL Query Select ID from TableName where SessionID = sessionID;
I think this will help you.
这篇关于如何使用sqlbulkcopy获取primarkey值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文