title: How to get number of rows using SqlDataReader in C#
body: <p>My question is how to get the number of rows returned by a query using <code>SqlDataReader</code> in C#. I've seen some answers about this but none were clearly defined except for one that states to do a while loop with <code>Read()</code> method and increment a counter.</p>
  
  <p>My problem is that I am trying to fill a multi-dimensional array with the first row being the column header names and every row after that to the be the row data. </p>
  
  <p>I know that I can just dump the stuff in a List control and not worry about it, but for my own personal edification and I would also like to pull the data in and out of the array as I choose and display it in different formats.</p>
  
  <p>So I think I can't do the <code>Read()</code> and then increment ++ way because that means that I would have to open <code>Read()</code> and then open <code>Read()</code> again to get amount of rows and then column data.</p>
  
  <p>Just a small example of what I'm talking about:</p>
  
  <pre><code>int counter = 0;    
  
  while (sqlRead.Read())
  {
      //get rows
      counter++
  }
  </code></pre>
  
  <p>and then a for loop to run through the columns and pop</p>
  
  <pre><code>something.Read();
  
  int dbFields = sqlRead.FieldCount;
  
  for (int i = 0; i &lt; dbFields; i++)
  {
     // do stuff to array
  }
  </code></pre>