我得到'data is null'异常 [英] I get 'data is null' exception

查看:731
本文介绍了我得到'data is null'异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我得到了异常'Data is Null。无法在Null值上调用此方法或属性。'at line if(reader1 ...)



In the following code I get the exception 'Data is Null. This method or property cannot be called on Null values.' at line if(reader1...)

while (reader1.Read())
if(reader1.GetDateTime(9) !=null)

推荐答案

您好,

我认为你的读者1没有价值。请检查是否有。然后回来。



或者,读者1上没什么可读的。

谢谢。
Hi,
I think your reader1 doesn't have a value. Please check if it has. Then come back.

Or, there's nothing to read on reader1.
Thanks.


试试这个



int x = reader.GetOrdinal(datefield);



if(!reader) .IsDBNull(x))

dateValue = reader.GetDateTime(x);
Try this

int x = reader.GetOrdinal("datefield");

if(!reader.IsDBNull(x))
dateValue = reader.GetDateTime(x);


这里只有当reader1不包含任何值时才会出现异常。但是你在循环时检查这个。所以修改你的代码如下:

Here the exception comes only if the reader1 doesn't contain any value . But you are checking this while while loop . So modify your code as below :
while (reader1.Read())
{
if(reader1.GetDateTime(9) !=null)



//你的逻辑在这里

}


//your logic here
}


这篇关于我得到'data is null'异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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