Link to home
Start Free TrialLog in
Avatar of zachvaldez
zachvaldezFlag for United States of America

asked on

defining NULL or 0

The value on my field is 0. How will I express it when using a datareader?
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

if ( field.value == DBNull.Value )
or
if (DBNull.Value.equals(field.value))

see here
https://msdn.microsoft.com/en-us/library/system.convert.isdbnull(v=vs.110).aspx
Avatar of zachvaldez

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) 

Open in new window

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)   ??
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 ) )
(dr ["field name"]  != 0 ) )... this part I get error that says  I have to cast  left hand side to string
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
Item.checked = (dr ["field name"]  == 1);

Should be shortest, then ...
there is no intellisense on item.checked
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial