Silv3rSurf3r_20 Posted June 13, 2003 Posted June 13, 2003 Hey All, I have a quick question... how do i get a count of how many records are selected when i execute a SELECT query... like when it was in ADO with the use of .recordcount How do i do this in ADO.net Thanks ~John~ Quote
wyrd Posted June 13, 2003 Posted June 13, 2003 Doesn't the xxxDataReader class have a Count property? If not then doing an xxxCommand.ExecuteScalar on SELECT COUNT(*) FROM table is the only thing I can think of. Quote Gamer extraordinaire. Programmer wannabe.
Mehyar Posted June 13, 2003 Posted June 13, 2003 The datareader doesnot have a count property. What you can do is that use a dataadapter and fill the results in a table by using the Fill method, and then count the rows of that table. 'sample code Dim da as new dataadapter("Select ....","Connection string") dim dt as new datatable() da.fill(dt) dim recordcount as integer = dt.rows.count Hope this helps... Quote Dream as if you'll live forever, live as if you'll die today
ashrobo Posted June 13, 2003 Posted June 13, 2003 While MyReader.Read Count += 1 End While Msgbox(Count) i am using the abovementioned code.. -ashrobo Quote
wyrd Posted June 13, 2003 Posted June 13, 2003 Ah, DataTable. I knew there was something that had the Count property. Quote Gamer extraordinaire. Programmer wannabe.
Leaders quwiltw Posted June 14, 2003 Leaders Posted June 14, 2003 ashrobo, if that's all you're doing with the data is looping through to count it you'd likely do well by taking wyrd's recommendation and letting the db do the count for you. Quote --tim
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.