zachvaldez
asked on
defining NULL or 0
The value on my field is 0. How will I express it when using a datareader?
ASKER
like .. if (dr ["field name"])==DBNull.Value)
yes, exactly, just you posted a ) too much after dr ["field name"] :
if (dr ["field name"] ==DBNull.Value)
ASKER
the reason I'm asking this is because, I want to put a check on the checklistbox and there are 5 of them. My way of thinking this is index for each checklistbox . So if 1 is the value it is checked on page load and if 0 , uncheck it. Does that make sense. The index are from 0 to 4.
So if it is 1 then
if (dr ["field name"] ==!DBNull.Value) ??
So if it is 1 then
if (dr ["field name"] ==!DBNull.Value) ??
to check if the fields is "not" NULL:
if (dr ["field name"] != DBNull.Value)
to check if the value is not NULL and <> 0:
if ( (dr ["field name"] != DBNull.Value ) && (dr ["field name"] != 0 ) )
if (dr ["field name"] != DBNull.Value)
to check if the value is not NULL and <> 0:
if ( (dr ["field name"] != DBNull.Value ) && (dr ["field name"] != 0 ) )
ASKER
(dr ["field name"] != 0 ) )... this part I get error that says I have to cast left hand side to string
ASKER
btw, it sees the value of zero as != DBNull.Val, therefore it marks the checkbox.. It should only mark when it is 1
so the definition of dbNull won't apply. Id like to test condition as 1 or 0
so the definition of dbNull won't apply. Id like to test condition as 1 or 0
Item.checked = (dr ["field name"] == 1);
Should be shortest, then ...
Should be shortest, then ...
ASKER
there is no intellisense on item.checked
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or
if (DBNull.Value.equals(field
see here
https://msdn.microsoft.com/en-us/library/system.convert.isdbnull(v=vs.110).aspx