2011-04-02 164 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