You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've come across an issue when trying to use InsertBulk with nullable bools saved as nullable bits in a SQL Server database.
If the first row of data sets a value (true or false) then subsequent nulls in the column are imported as expected.
However, if the first row's value is null, as soon as a subsequent row has a non-null value the following exception occurs: Cannot change DataType of a column once it has data.
This happens In SqlBulkCopyHelper - in debug you can see that the DataType has been set as {Name = "Boolean" FullName = "System.Boolean"} and wants to be changed to {Name = "Int32" FullName = "System.Int32"}
I've come across an issue when trying to use
InsertBulk
with nullable bools saved as nullable bits in a SQL Server database.If the first row of data sets a value (true or false) then subsequent nulls in the column are imported as expected.
However, if the first row's value is null, as soon as a subsequent row has a non-null value the following exception occurs:
Cannot change DataType of a column once it has data.
This happens In SqlBulkCopyHelper - in debug you can see that the DataType has been set as
{Name = "Boolean" FullName = "System.Boolean"}
and wants to be changed to{Name = "Int32" FullName = "System.Int32"}
This is where the exception is occurring.
As a temporary fix, I've made a copy of SqlBulkCopyHelper and made a tweak to BuildBulkInsertDataTable where it sets the column type.
I have replaced:
with:
This works by forcing the type to int if it's a boolean.
Is there a better way to handle InsertBulk with nullable bools?
The text was updated successfully, but these errors were encountered: