检查VB.net数据集表是否存在

use*_*480 2 vb.net if-statement dataset

我有以下代码来检查我的表是否存在,然后再继续

        If ds.Tables(3).Rows.Count = 0 Then
            MsgBox("Nothing!!!!")
        Else
            DataGridView1.DataSource = ds.Tables(3)
Run Code Online (Sandbox Code Playgroud)

问题是我不断收到错误“找不到表 3”。

在VB中我如何检查表是否存在,而不是我的应用程序出错,我只是希望它在表不存在时不执行任何操作。

我也尝试过

If ds is nothing
Run Code Online (Sandbox Code Playgroud)

非常感谢任何帮助。

小智 5

如果您不确定数据集是否存在,请查看数据集是否包含该表:

If mdsMyDataSet1.Tables.Contains("Table3") = True Then
   'Do Something with it
End If
Run Code Online (Sandbox Code Playgroud)