mousemat24
asked on
Object cannot be cast from DBNull to other types - using SQL 2000/C#
Hi there
Wonder if you can help me, I keep getting the following error:
Object cannot be cast from DBNull to other types.
I have the following code:
dateSend_ADHOC = myDataReader["DT_SEND"].To String();
if (dateSend_ADHOC == "") // I guess I get the error here?
{
.
.
.
.
}
dateSend_ADHOC could have a date or left blank i.e. in SQL left as null
How do I get this to work?
Many thanks
Mousemat24
Wonder if you can help me, I keep getting the following error:
Object cannot be cast from DBNull to other types.
I have the following code:
dateSend_ADHOC = myDataReader["DT_SEND"].To
if (dateSend_ADHOC == "") // I guess I get the error here?
{
.
.
.
.
}
dateSend_ADHOC could have a date or left blank i.e. in SQL left as null
How do I get this to work?
Many thanks
Mousemat24
Or...
returnValue = Convert.IsDBNull(value)
returnValue = Convert.IsDBNull(value)
ASKER
When I do the following - if (dateSend_ADHOC == System.DBNull.Value)
I get the following error:
Error 1 Operator '==' cannot be applied to operands of type 'string' and 'System.DBNull'
I get the following error:
Error 1 Operator '==' cannot be applied to operands of type 'string' and 'System.DBNull'
or jsut query length of resulting string, if its 0, then input field was empty or null
dateSend_ADHOC = myDataReader["DT_SEND"].To String();
if (dateSend_ADHOC.Length == 0) // I guess I get the error here?
{
...
}
dateSend_ADHOC = myDataReader["DT_SEND"].To
if (dateSend_ADHOC.Length == 0) // I guess I get the error here?
{
...
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
not positive but try...
if (dateSend_ADHOC == System.DBNull.Value) // I guess I get the error here?
{
.
.
.
.
}