Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

record count

Status
Not open for further replies.

baran121

Programmer
Sep 8, 2005
337
TR
Hi everybody,

i wanna learn how to get count data of SqlDataReader.
here is my code;

cmd1 = new SqlCommand(" select cre_usr,cre_date,orders from orderr ", conn);
rdr = cmd1.ExecuteReader();

after that i need to know recordcount

thanks.


 
I would use a SqlDataAdapter's fill method to populate a DataTable. Then you can:

Code:
var rowCount = dataTable.Rows.Count

 
hi,
i can not see rows.Count for SqlDataAdapter ?

 
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.

Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top