我从数据库中检索数据,如下所示.如何检查从数据库检索的值是否为空?
Private Function GetBatch() As DataSet Dim dataset As New DataSet Dim adapter As Data.SqlClient.SqlDataAdapter Dim cn As New System.Data.SqlClient.SqlConnection(connectionstring()) GetBatchCommand.Connection = cn adapter = New Data.SqlClient.SqlDataAdapter(GetBatchCommand) adapter.Fill(dataset) Return dataset End Function Dim dataset As New DataSet dataset = GetBatch() With dataset.Tables(0) Dim PersonID As String = .Rows(int).Item("personId")
我想检查personID是否为null.怎么办?
尝试DataRow的IsNull方法来检查空值:
Dim isPersonIDNull As Boolean = .Rows(0).IsNull("personId")
或者使用IsDBNull方法:
Dim isPersonIDNull As Boolean = IsDBNull(.Rows(int).Item("personId"))
或者手动检查值是否等于DBNull:
Dim isPersonIDNull As Boolean = .Rows(int).Item("personId").Equals(DBNull.Value)