I've scoured stack overflow for the answer to my problem but nothing matches my situation.
I've got a struct which represents the schema of data retrieved from a stored procedure. the data type for a boolean field is nullable, but when the value returned is null, I cannot assign the value to the list item.
Struct looks like this:
public GuidelineSchema gl;
public struct GuidelineSchema
{
public int id;
public int GLtypeID;
public int typeValue;
public Nullable<bool> isInlineLayout;
public int ResinGroupID;
public int NotResinGroupID;
public int ResinSubTypeID;
.
.
.
}
and I populate it here
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
GuidelineSchema gl = new GuidelineSchema() {
id = sdr.IsDBNull(0) ? 0 : sdr.GetInt32(0),
GLtypeID = sdr.IsDBNull(1) ? 0 :sdr.GetInt32(1),
typeValue = sdr.IsDBNull(2) ? 0 : sdr.GetInt32(2),
//isInlineLayout = sdr.IsDBNull(3) ? (bool?)null : sdr.GetBoolean(3),
//isInlineLayout = (bool?)sdr.GetSqlBoolean(3),//.GetBoolean(3),
//isInlineLayout = (Nullable<Boolean>)sdr.GetBoolean(3),// sdr.IsDBNull(3) ? : sdr.GetBoolean(3),//sdr.IsDBNull(3) ? false :
//isInlineLayout = sdr.IsDBNull(3) ? (bool?)null : sdr.GetSqlBoolean(3),
isInlineLayout = sdr.GetBoolean(3),
ResinGroupID = sdr.IsDBNull(4) ? 0 : sdr.GetInt32(4),
NotResinGroupID = sdr.IsDBNull(5) ? 0 : sdr.GetInt32(5),
.
.
.
The problem occurs only when the db value is null. I've tried all the different checks, and casts, each time I get the error. I've read up on sql data types, nullable data types. It works if i set the value to true or false if it's null, but I actually need it to be null if it's null.
Anyone know how I can get this done and allow the value to be null when it is supposed to be?