Nigel_Taylor
asked on
ASP.NET C# DBNull Check
Hi Guys,
In ASP.NET c# I need to do an IF to statement to check if a field is null or not. The field is a datetime field. Can anyone see what I am doing wrong?
if (Convert.ToDateTime(userDa ta["Connec tionDateTi me"]) == System.DBNull)
I am am getting the error System.DBNull is a 'type', which is not valid in the given context.
Hope you can help.
Regards,
Nigel
In ASP.NET c# I need to do an IF to statement to check if a field is null or not. The field is a datetime field. Can anyone see what I am doing wrong?
if (Convert.ToDateTime(userDa
I am am getting the error System.DBNull is a 'type', which is not valid in the given context.
Hope you can help.
Regards,
Nigel
ASKER
Cool,
I am getting the following error now on the same line.
Operator '==' cannot be applied to operands of type 'System.DateTime' and 'System.DBNull'
Regards,
Nigel
I am getting the following error now on the same line.
Operator '==' cannot be applied to operands of type 'System.DateTime' and 'System.DBNull'
Regards,
Nigel
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect.
Thanks for the quick response.
Regards,
Nigel
Thanks for the quick response.
Regards,
Nigel
Or you could try
if (Convert.ToDateTime(myValu e).Equals( System.DBN ull.Value)
if (Convert.ToDateTime(myValu
Use System.DBNull.Value instead.
Jas.