开发者

Whats the proper way to check to see if an entry in a db table is null?

I have a sub that updates a form on certain occasions. Sometimes I need to update a form when some of the entries in my table will still have a NULL value. I use开发者_如何学Pythond this code to prevent the sub from trying to fill the form fields with NULL data:

    If IsDBNull(CID.Single().Age) = False Then
        txtAge.Text = CID.Single().Age
    End If

But I am getting the error "Nullable object must have a value." when it tries to fill txtAge.Text. This method is working on other fields.

If CID.Single().Age is NULL then shouldnt it skip this action?


The error you got ("Nullable object must have a value.") suggests that Age is a nullable object.

When testing a nullable type for a value, use the HasValue property to see if it holds an actual value.

If CID.Single().Age.HasValue Then
    txtAge.Text = CID.Single().Age
End If


Compare it to dbnull.value as in

if row("value") is dbnull.value then do X

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜