检查DataTable是否有行的有效方法

Ang*_*Wat 9 vb.net datatable

我有一个搜索关键字然后返回DataTable的函数.我想检查里面是否有行,因为有时候找不到查询.

    'which one shoud I use ?
    If dtDataTable Is Nothing Then
        'some code
        lbl_count.Text = "Found 0 result"
    End If

    If dtDataTable.Rows.Count > 0 Then
        'some code
        lbl_count.Text = "Found " & dtDataTable.Rows.Count.ToString & " results"
    End If
Run Code Online (Sandbox Code Playgroud)

谢谢.

小智 24

怎么样:

If dtDataTable IsNot Nothing AndAlso dtDataTable.Rows.Count > 0 Then
    'some code
    lbl_count.Text = "Found " & dtDataTable.Rows.Count.ToString & " results"
Else
    'some code
    lbl_count.Text = "Found 0 result"
End If
Run Code Online (Sandbox Code Playgroud)