2011-04-02 171 views
1

如何检查数据集是否为空? 我写了下面的代码:检查vb.net数据集是否为空

Dim da As New SqlDataAdapter("query",connection string) 
da.Fill(ds) 
If (Not (ds.Tables.Count > 0)) Then 
    Response.Redirect("norecords.aspx?str1=" + str1) 
end if 

在if条件,我无法访问ds.Tables[0].rows.count。我应该怎么做?

回答

0
Dim cm As New OleDbCommand("Select * from Table1", cn) 
da = New OleDbDataAdapter(cm) 

If (ds.Tables.Contains("Table1") = False) Then 
    da.Fill(ds, "Table1") 
End If