Get id of new row during reading csv file.

18 views
Skip to first unread message

Борис Илларионов

unread,
Mar 24, 2016, 8:40:45 AM3/24/16
to CSVChat
Hello! Is it possible to get id of new row before inserting to database?
Thanks for advace!

shriop

unread,
Mar 24, 2016, 9:04:49 AM3/24/16
to CSVChat
Are you talking about when using SqlBulkCopy? If so, the only way to know the id of an identity column before it has been inserted into the database would be to calculate it ahead of time and insert values for the identity value instead of letting the database assign them. To do this, you have to set KeepIdentity on the SqlBulkCopyOptions, https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopyoptions.aspx . If you're using DataStreams, you'll also probably be using the ReadRecord event to set the identity value, http://www.csvreader.com/csv/docs/html/E_DataStreams_Common_DataReaderBase_ReadRecord.htm .

Bruce Dunwiddie
Reply all
Reply to author
Forward
0 new messages