I have a datareader. I need to find the number of rows in it so that I can instantiate an array. Initially I did this by using:
<code>
DataTable dt = new DataTable();
dt.Load(reader);
int noOfRows = dt.Rows.Count;
</code>
However I found that loading the reader into the datatable will close the reader before I am able to iterate through it later in my code. I was thinking of cloning the reader and passing the clone to the Datatable. Is this possible or advisable?
Is there a better way of finding the number of rows in my data reader? I know I could do something with a list (not fully sure what) but my datareader contains 33 fields of varying data types and I dont know how to put that all into a list.
thanks
while (reader.Read() && (i != noOfRows))
In other words how do i loop a datatable? – Gavin Jun 09 '16 at 13:22