I have a SQL Server table where the 1st column ID
is primary identity column, 2nd column is BatchId
which is also part of the primary key.
In datatable dt
, I am adding column batchId
explicitly. When inserting from the datatable to SQL Server using SqlBulkCopy
, I am assigning same value to batchId
column (for e.g. for today's date batchId
will be 1
, for next date batchId
will be 2
and so on), but SqlBulkCopy
states error
Cannot insert null values to column BatchId from table 'xxxx'";
despite assigning values. I have also passed the SqlBulkCopyOptions.KeepIdentity
& SqlBulkCopyOptions.KeepNulls
parameters to SqlBulkCopy
class.
Any help appreciated, thanks in advance!