Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Null Boolean conundrun
Message
From
12/08/2014 16:45:00
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 5.0
OS:
Windows 8
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01605517
Message ID:
01605521
Views:
28
System.Boolean??? That's a lot of extra typing that isn't needed.

I can't guarantee this will work for your case, but I just do something like:
public bool? MasterStandBy;

>Hi All, (Not sure if Forum and Category are right, but I could not find c# as a forum or category)
>
>I had a program working fine, until I decided I wanted to save null values into the database (which accepts nulls for the fields), the problem seems to be related to Boolean types, as it did not complain about other types (yet), for example I have something like this:
>
>
>                public System.Boolean? MasterStandBy = null;
>
>
>
>later on a Save method:
>
>
>                System.Data.DataRow newDataRow = dataTable.NewRow();
>...
>                newDataRow["Cmd_MasterStandBy"] = MasterStandBy; 
>...
>                dataTable.Rows.Add(newDataRow);
>
>
>
>And the column is defined as
>
>
>            Columns.Add(new System.Data.DataColumn("Cmd_MasterStandBy", typeof(System.Boolean)));
>
>
>I tried a lot of different options, this gives me the error "System.ArgumentException: Cannot set Column 'Cmd_MasterStandBy' to be null. Please use DBNull instead.", Now, I tried lots of different things, for example
>
>
>                newDataRow["Cmd_MasterStandBy"] = MasterStandBy?? System.DBNull.Value; //Does not even compile
>
>
>Change all Boolean types to be System.Data.SqlTypes.SqlBoolean?, tried typeof(System.Boolean?), typeof(System.Data.SqlTypes.SqlBoolean), typeof(System.Data.SqlTypes.SqlBoolean?) and many other things that I found googling, but I cannot solve this issue, what should I do?
>
>TIA,
>Hugo
>
>PS. By the way, I use this table to update the SQL Server table using sqlBulkCopy, and it was working great when I initialized all the values to default{T} (false, zero etc), problems started when I initialized the values to null, and apparently only with the Boolean type
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform