Vb.net 从类型转换为';DBNull';输入';整数';无效

Vb.net 从类型转换为';DBNull';输入';整数';无效,vb.net,gridview,Vb.net,Gridview,我想在PendingApproval值上设置可见性的开或关,但在数据库PendingApprovalfield中是allow null true,所以我得到的错误是代码 从类型“DBNull”到类型“Integer”的转换无效 style="margin-left:6px; margin-top:auto; display:<%# IIf(CTYPE(Eval("PendingApproval"),Integer) = 1, "block", "none")%>" style=

我想在PendingApproval值上设置可见性的开或关,但在数据库PendingApprovalfield中是allow null true,所以我得到的错误是代码

从类型“DBNull”到类型“Integer”的转换无效

 style="margin-left:6px; margin-top:auto; display:<%#  IIf(CTYPE(Eval("PendingApproval"),Integer) = 1, "block", "none")%>"
style=“左侧边距:6px;顶部边距:自动;显示:”

试试这个。我假设如果该值为空,那么可见性需要设置

style="margin-left:6px; margin-top:auto; display:<%# IIf(Eval("PendingApproval")=DBNull.value,"none", IIf(Eval("PendingApproval") = 1, "block", "none"))%>"

通过这种方式,NULL的值将为0,而旧代码在不比较DBNull的情况下也能正常工作。我假设如果该值为空,那么可见性需要设置

style="margin-left:6px; margin-top:auto; display:<%# IIf(Eval("PendingApproval")=DBNull.value,"none", IIf(Eval("PendingApproval") = 1, "block", "none"))%>"

通过这种方式,您将得到NULL的值0,并且您的旧代码在不比较DBNull的情况下运行良好。value

为了防止该错误,您可以尝试以下操作

style="margin-left:6px; margin-top:auto; display:<%#Iif(Eval("PendingApproval") Is Null,"none",IIf(CTYPE(Eval("PendingApproval"),Integer) = 1, "block", "none"))%>"
style=“左侧边距:6px;顶部边距:自动;显示:”

为防止出现此错误,请尝试以下操作

style="margin-left:6px; margin-top:auto; display:<%#Iif(Eval("PendingApproval") Is Null,"none",IIf(CTYPE(Eval("PendingApproval"),Integer) = 1, "block", "none"))%>"
style=“左侧边距:6px;顶部边距:自动;显示:”

Solution here:Solution here:我使用了这个,但出现了错误BC30452:没有为类型“Object”和“System.DBNull”定义运算符“=”。也使用==但其也不工作我使用此命令,但出现错误BC30452:未为类型“Object”和“System.DBNull”定义运算符“=”。也使用==但它也不起作用