Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can any one tell me .. how to show the nmber of rows in a db table which are executed using count sql query in a label. for example if we have a query

C#
"Select Count(*) FROM Categories where CategoryName ='" + p.addcat + "'";


and we lets say we get two rows by this count query. i want to show that count=2 in a label control.. how can i do it??
Posted
Comments
codegeekalpha 13-Feb-12 19:07pm    
sql ado.net

1 solution

once you have data in the data table , try something like :
C#
Label1.Text = datatable.Rows[0][0].ToString();

Although if you are only getting one value out of the database, ExecuteScalar() would be better.
 
Share this answer
 
v2
Comments
Anuja Pawar Indore 14-Feb-12 2:43am    
Added pre tag

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900