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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determining number of query records...

Status
Not open for further replies.

Sheffield

Programmer
Jun 1, 2001
180
US
Greetings,

I'm a .NET newbie unable to determine the number of records being returned by a query. I was expecting a RecordCount property or something, but I can't find any documentation on it. Ugh!!!

Can someone please clue me in?

Thanks:)
 
Depends what type of Data Control you'll be using. Please elaborate.
 
well, in one instance, I'm populating a DataGrid and in another I'm populating a DropDownList.

I just need to make some decisions in the code based on the presence or absence of records returned by the query.

I realize I could perform an additional query using
Code:
SELECT Count(*) FROM...
via the ExecuteScalar method but that seems like there should be a more simple way to achieve the same result.

Thanks:)
 
You can use a SqlDataReader object to bind your controls to and use its HasRows property:
Code:
if(myReaderHasRows)
{
 //bind control
}
else
{
  // display "No Records" message
}
 
Sorry, should read
Code:
if(myReader.HasRows)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top