本文介绍了从sql计数投票并使用asp.net显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一款用于移动投票的Android应用。支持我已经制作了一些.aspx页面。现在,我被困在一个我需要制作一个页面的地方,其中应该显示投票计数以及竞争者名称和聚会名称。我在sql数据库中有一个表 RegisterContender ,它包含 ContenderName PartyName 。我还有一个表 castVote ,其中包含选民投票的 ContenderName 。现在我要做的是计算选民投票的 ContenderName (s)的数量并以表格形式显示: - 名称PartyName TotalVotes



我尽快...谢谢







String _view = String.Format(select count(*)as numVotes,contenderName from castVote,其中ContenderName IS NOT NULL group by ContenderName order by numVotes desc);



SqlCommand cmd = new SqlCommand(_view,con);

SqlDataReader dr = cmd.ExecuteReader();



while(dr。阅读())

{



String _ans = String.Format(dr [numvotes]。ToString()++ dr [ContenderName]。ToString());



Response.Write(_ans);

}


$ b

表结构



创建表RegisterContender

(ContenderId int identity(1,1)主键不为空,

名称varchar(100),

Party名称varchar(100),

历史varchar(1000),

Future_Proposals varchar(500),

Region varchar(150)





创建表castVote

(VoterLogin varchar(100),ContenderName varchar(100))



这两者之间的关系是来自castVote的ContenderName与RegisterContender中的Name相同。 PartyName也出现在RegisterContender中。

i am making an android app for mobile voting. to support that i have made some .aspx pages. now i am stuck at a point where i have to make a page in which vote count along with the contender name and the party name should be shown. i have a table RegisterContender in sql database which consists of the ContenderName and PartyName. i also have a table castVote which consists of the ContenderName for which the voter has voted. Now what i want to do is to count the number of ContenderName(s) for which the voters have voted and display it in the form:- Name PartyName TotalVotes

hep me asap.. thank you



String _view = String.Format("select count(*) as numVotes,ContenderName from castVote where ContenderName IS NOT NULL group by ContenderName order by numVotes desc");

SqlCommand cmd = new SqlCommand(_view, con);
SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())
{

String _ans = String.Format(dr["numvotes"].ToString()+" "+dr["ContenderName"].ToString());

Response.Write(_ans);
}


table structure

create table RegisterContender
(ContenderId int identity(1,1) Primary Key Not Null,
Name varchar(100),
PartyName varchar(100),
History varchar(1000),
Future_Proposals varchar(500),
Region varchar(150)
)

create table castVote
(VoterLogin varchar(100),ContenderName varchar(100))

the relationship between these two is that the ContenderName from castVote is same as the Name in the RegisterContender. PartyName is also present in the RegisterContender.

推荐答案

select count(*) as numVotes,cv.ContenderName,rc.PartyName
from castVote cv inner join RegisterContender rc on cv.ContenderName = rc.Name
where ContenderName IS NOT NULL
group by ContenderName order by numVotes desc


这篇关于从sql计数投票并使用asp.net显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 20:02