title: How can I check whether a dataset is empty or not in C#.net
body: <p>I seen this question - how can I check whether a dataset is empty or not in C#.net - on a site for C# interview questions.</p>
  
  <p>Someone answered:</p>
  
  <pre><code>DataSet ds = &lt;get a dataset somehow&gt;;
  
  if (ds != null &amp;&amp; ds.Tables.Count &gt; 0 &amp;&amp; ds.Tables[0].Rows.Count &gt; 0)
  {
      // There is something in the DataSet.
  }
  </code></pre>
  
  <p>I'm some what new to C# and I am thinking there is more to this.</p>
  
  <p>1.) Because he specified the zero index of the tables property, is that an assumption that there is only 1 table in the dataset? If there is only 1 table, then I understand that this will work.</p>
  
  <p>2.) However, if there is more than 1 table, then am I correct to say that the above code would NOT determine if the dataset is empty?</p>
  
  <p>If I am correct [#2], then would this be the way to determine whether the dataset is empty or not?</p>
  
  <pre><code>        DataSet ds = &lt;get a dataset somehow&gt;;
  
          bool dataFound = false;
  
          // Check to see if the dataset actually exists.
          // Check if it has one or more tables.
  
          if( ds != null &amp;&amp; ds.Tables.Count &gt; 0 )
          {
              // Check the row count for each table to see if any one table has data.
              foreach( System.Data.DataTable table in ds.Tables )
              {
                  if( table.Rows.Count &gt; 0 )
                  {
                      //we have data
                      dataFound = true;
                      break;
                  }
              }
          }
  
          if( dataFound )
          {
              Console.WriteLine( "we have data" );
          }
          else
          {
              Console.WriteLine( "we have NO data" );
          }
  </code></pre>
  
  <p>Regards...Dan</p>