Checking datasets for tables and rows Is there a cleaner way of checking a dataset for tables/rows before attempting to read them?

If ds.Tables.Count &gt; 0 Then
    If ds.Tables(0).Rows.Count &gt; 0 Then

        'do something with the the rows at this point

    End If
End If


Edit to clarify - I am talking specifically about the two bool checks to see if the dataset acutally contains any data in table(0).
I'm doing a couple of assumptions here, but I hope I'm on target.

If you just want the first column of the first row, you should use SqlCommand.ExecuteScalar instead of reading it into a dataset.

For instance:

using (var cn = new SqlConnection("..."))
{
    using (var cmd = new SqlCommand("SELECT statusCode FROM table WHERE whatever", cn)
    {
        cn.Open();
        return (string)cmd.ExecuteScalar();
    }
}


(Notice the using statement if you don't know it. It automatically disposes the connection and command)

You could also look into using SqlCommand.ExecuteReader which returns an SqlDataReader. The latter is cleaner and has better performance than the dataset method too. 

using (var reader = cmd.ExecuteReader())
{
    while(reader.Read()) 
    { 
        var value = reader.GetString(0); 
    }
}