问题描述
大家好
我在sqldataserver中有一个带有此列的表:
课程名称
CourseId
StudentId
并使用以下数据:
数学1115 8684612
数学1115 8684613
数学1115 8684614
操作系统1116 8684612
操作系统1116 8684615
操作系统1116 8684613
我想通过Asp.net&C#
在gridview中显示课程名称和课程名称计数
例如:
课程名称计数
数学3
操作系统4
请帮助我
昂给我任何代码
谢谢....
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....
推荐答案
select Coursename, COUNT(Coursename) as [Count]
from *typeHereYourTableName"
group by Coursename
显然是按顺序排列的,而不是按顺序排列的...我很困惑.
[/EDIT]
it''s obviously group by not order by... i''am confused.
[/EDIT]
select Coursename, COUNT(Coursename) as [Count]
from tablename
group by Coursename
希望对您有所帮助.
i hope this will help you.
select coursename,count(coursename) as NoOfcount from tablename group by coursename.
将gridview绑定为
bind gridview as
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();
这篇关于我想通过Asp.net& C#在gridview中显示课程名称和课程名称计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!