Click here to Skip to main content
15,921,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
I have one table in sqldataserver with this column:
Coursename
CourseId
StudentId

and with this data:


mathmatic 1115 8684612
mathmatic 1115 8684613
mathmatic 1115 8684614
operatingSystem 1116 8684612
operatingSystem 1116 8684615
operatingSystem 1116 8684613


I want to display in gridview Coursename and Count of Coursename via Asp.net&C#

For Exmple:


Coursename Count
mathmatic 3
operatingSystem 4


Please help me
ang give me any code for this
Thank you....
Posted

try this (I gues that you use SQL Server)


SQL
select Coursename, COUNT(Coursename) as [Count]
from *typeHereYourTableName"
group by Coursename



[EDIT]

it's obviously group by not order by... i'am confused.

[/EDIT]
 
Share this answer
 
v2
SQL
select Coursename, COUNT(Coursename) as [Count]
from tablename
group by Coursename


i hope this will help you.
 
Share this answer
 
use this query to bind your gridview
SQL
select coursename,count(coursename) as NoOfcount from tablename group by coursename.

bind gridview as
C#
string str = "select coursename,count(coursename) as NoOfcount from tablename group by coursename";
        SqlDataAdapter da = new SqlDataAdapter(str, Db.GetConnection());
         DataTable table = new DataTable();
        table.Locale = System.Globalization.CultureInfo.InvariantCulture;
        da.Fill(table);
        GridView1.DataSource = table;
        GridView1.DataBind();
 
Share this answer
 
v3
Hi,
First you need to connect with the database.
Then use the following logic...

SqlCommand cmd= new SqlCommand("select Coursename, COUNT(Coursename) as Count
from *Table_Name", connection string name);

SqlDataReader sdr = cmd.ExecuteReader();
GridView1.DataSource = sdr;
GridView1.DataBind();
 
Share this answer
 

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