This might need tweeked a little bit, but this will load data into DataTable and then you can get the rows.
Code:
var conn = new SqlConnection("connectionString");
var da = new SqlDataAdapter(new SqlCommand("select * from blah", conn));
var dt = new DataTable();
da.Fill(dt);
var rowCount = dt.Rows.Count;
Wrote this quick out of my head without compiling but for most part should work.
DataTable is different from DataReader as the DataReader only goes forward and doesn't really know ahead of time how many rows exist. DataTable loads a "table" based on your query into memory so it contains a row count. I have been programming in .NET for years and have never used DataReader myself although I have worked on programs that have used it. I prefer DataTables or DataSets.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.