我的if陈述出现问题 [英] Problems with my if statement

查看:116
本文介绍了我的if陈述出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,谢谢您看我的问题.我有2条if语句:

Hi All, Thanks for looking at my question. I have 2 if statements:

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


我收到错误消息无法将类型"System.DBNull"转换为"int""
任何建议或意见将不胜感激.
谢谢
D


I am getting the error "Cannot convert type ''System.DBNull'' to ''int''"
Any suggestions or input would be greatly appreciated.
Thank-you,
D

推荐答案

解决方案是在尝试进行转换之前对值进行null检验.
The solution is to do an is null check on the value before attempting a conversion.
if( recordset("IsLocked") != DBNull.Value && (int)recordset("IsLocked").VALUE == 1) ...


这篇关于我的if陈述出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆