How to test if a DataSet is empty?

MCS picture MCS · Jun 4, 2010 · Viewed 197.2k times · Source

I'm modifying someone else's code where a query is performed using the following:

DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sqlString, sqlConn);
da.Fill(ds);

How can I tell if the DataSet is empty (i.e. no results were returned)?

Answer

rosscj2533 picture rosscj2533 · Jun 4, 2010

If I understand correctly, this should work for you

if (ds.Tables[0].Rows.Count == 0)
{
    //
}