如何在VB.NET中检查Null值 [英] How to check for a Null value in VB.NET

查看:115
本文介绍了如何在VB.NET中检查Null值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个:

If String.IsNullOrEmpty(editTransactionRow.pay_id.ToString()) = False Then
    stTransactionPaymentID = editTransactionRow.pay_id 'Check for null value
End If

现在,当 editTransactionRow.pay_id 为Null Visual Basic引发异常。这段代码有什么问题吗?

Now, when editTransactionRow.pay_id is Null Visual Basic throws an exception. Is there something wrong with this code?

推荐答案

如果您使用的是强类型数据集,则应执行以下操作:

If you are using a strongly-typed dataset then you should do this:

If Not ediTransactionRow.Ispay_id1Null Then
    'Do processing here
End If

您会收到此错误,因为强类型的数据集会检索基础值并通过该属性公开转换。例如,这实际上是正在发生的事情:

You are getting the error because a strongly-typed data set retrieves the underlying value and exposes the conversion through the property. For instance, here is essentially what is happening:

Public Property pay_Id1 Then
   Get
     return DirectCast(me.GetValue("pay_Id1", short)
   End Get
   'Abbreviated for clarity
End Property

GetValue方法返回的DBNull不能转换为short。

The GetValue method is returning DBNull which cannot be converted to a short.

这篇关于如何在VB.NET中检查Null值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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