SqlBulkCopy sqlBulk = new SqlBulkCopy(conn, SqlBulkCopyOptions.KeepIdentity, t);
sqlBulk.DestinationTableName = DestTableName;
sqlBulk.BatchSize = 1000;
sqlBulk.WriteToServer(dt);
t.Commit();
Error occurs if I assign my identity column value and if I do not assign it says "Null not allowed in primary key" column - what to do?
Please read below:
http://www.4guysfromrolla.com/articles/102109-1.aspx
OR
using (var bulkCopy = new SqlBulkCopy(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, SqlBulkCopyOptions.KeepNulls & SqlBulkCopyOptions.KeepIdentity))
{
bulkCopy.BatchSize = (int)DetailLines;
bulkCopy.DestinationTableName = "dbo.myTable";
bulkCopy.ColumnMappings.Clear();
bulkCopy.ColumnMappings.Add("SourceColumnName", "DestinationColumnName");
bulkCopy.ColumnMappings.Add("SourceColumnName", "DestinationColumnName");
bulkCopy.WriteToServer(datatable);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.