Live Chat Icon For mobile
Live Chat Icon

How to get the count of items in a dataReader

Platform: ASP.NET| Category: ADO.NET

VB.NET


Dim mycn As New SqlConnection('server=localhost;uid=sa;password=;database=northwind;')
Dim mycmd As New SqlCommand('Select * from Products', mycn)
mycn.Open()
Dim dr As SqlDataReader = mycmd.ExecuteReader
Dim i As Integer
While dr.Read
	i += 1
End While
Response.Write('Count of Records : ' & i)

C#


SqlConnection mycn =new SqlConnection('server=localhost;uid=sa;password=;database=northwind;');
SqlCommand mycmd = new SqlCommand ('Select * from Products', mycn);
mycn.Open();
SqlDataReader dr = mycmd.ExecuteReader();
int i=0;
while(dr.Read())
{
	i+=1;
}
Response.Write('Count of Records : ' + i.ToString());

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.