I use the SqlBulkCopy object to insert a couple of millions of generated rows into the database. The only problem is that the table I'm pasting into has an identifier column. I tried setting SqlBulkCopyOptions to SqlBulkCopyOptions.KeepIdentity and setting the identifier column 0 ', DbNull.Value and null . None of them worked. I feel like I am missing something quite simple if someone can enlighten me, which would be fantastic. Thank!
edit To clarify, I do not have the identification values ββset in the DataTable I import. I want them to be generated as part of the import.
edit 2 Here is the code that I use to create the base SqlBulkCopy object.
SqlBulkCopy sbc = GetBulkCopy(SqlBulkCopyOptions.KeepIdentity); sbc.DestinationTableName = LOOKUP_TABLE; private static SqlBulkCopy GetBulkCopy(SqlBulkCopyOptions options = SqlBulkCopyOptions.Default) { Configuration cfg = WebConfigurationManager.OpenWebConfiguration("/RSWifi"); string connString = cfg.ConnectionStrings.ConnectionStrings["WifiData"].ConnectionString; return new SqlBulkCopy(connString, options); }
c # sql-server sqlbulkcopy identity-insert
FlyingStreudel Jul 11 2018-11-11T00: 00Z
source share