Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All, Thanks for looking at my question. I have 2 if statements:

C#
if (recordset("IsLocked").VALUE != null)
        {
            if ((int)recordset("IsLocked").VALUE == 1)
            {
                Response.Redirect("../Lockout.aspx");
            }
        }

I am getting the error "Cannot convert type 'System.DBNull' to 'int'"
Any suggestions or input would be greatly appreciated.
Thank-you,
D
Posted
Comments
Sergey Alexandrovich Kryukov 19-Oct-12 15:14pm    
Who told you that the Value is integer? :-) This is the case when Value is not null, but DbNull, so check for DbNull first.
--SA

1 solution

The solution is to do an is null check on the value before attempting a conversion.
C#
if( recordset("IsLocked") != DBNull.Value && (int)recordset("IsLocked").VALUE == 1) ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900