I have a table where one of the fields is “InDatabase” (SQL Server “bit” type) which does not allow nulls.
I create a table and add a few hundred rows to it, where InDatabase is always assigned a value (InDatabase refers to whether the row is in another database)
When I call SqlBulkCopy, it is giving me an InvalidOperationException Error, with the message of:
"Column 'InDatabase' does not allow DBNull.Value."
Each Row Is Created as such:
ProductionDatabaseDataSet.EntriesV2Row NewRow = this.InsertTable.NewEntriesV2Row();
NewRow.MeetEntryID = MeetEntryID;
NewRow.EventID = EventID;
NewRow.MeetID = MeetID;
NewRow.AthleteID = AthleteID;
NewRow.Exhibition = Exhibition;
NewRow.Bonus = Bonus;
NewRow.EnterEvent = true;
NewRow.InDatabase = true;
if (AutoTime != null)
NewRow.AutoTime = AutoTime ?? -1;
if (CustomTime != null)
NewRow.CustomTime = CustomTime ?? -1;
this.InsertTable.AddEntriesV2Row(NewRow);
Then, after the above is called around 300 times, the SqlBulkCopy is called:
SqlBulkCopy bulkCopy = new SqlBulkCopy(this.Connection.ConnectionString);
bulkCopy.DestinationTableName = this.Adapter.TableMappings[0].DataSetTable;
bulkCopy.BatchSize = BatchSize;
bulkCopy.WriteToServer(InsertTable); //Throwing the error
I use this exact same format on about a dozen other tables with no problem.
OK, I got it to work, but not really figured it out. I changed the bulkCopy section to this:
Not real sure why the dozen other times I did this without setting the table mappings like this worked, but for some reason, with this table, it will not work unless I do the above.