我正在制作一个关于 android 上的移动投票的应用程序.. 以支持我在 asp.net 中有一些页面。现在我被困在我必须制作一个要进行投票的页面的地方......
我想出了这个...
该程序包括三个步骤..
第 1 步检查 id 和 _password 是否正确。
第 2 步检查表中是否存在竞争者名称。
第 3 步检查 id 是否存在于 castVote 表中,如果不存在,则将其与竞争者名称一起输入...
protected void Page_Load(object sender, EventArgs e)
{
Boolean step1 = false;
Boolean step2 = false;
Boolean step3 = false;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ToString());
try
{
con.Open();
String _view = String.Format("Select * from login_password where id='{0}' and _password='{1}'", Request.QueryString["id"].ToString(), Request.QueryString["_password"].ToString());
SqlCommand cmd = new SqlCommand(_view, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.HasRows)
{
step1 = true;
Response.Write("step1 fulfilled");
}
if(step1 == false)
{
// step1 = false;
Response.Write("Check User Details");
}
}
catch (Exception ee)
{
Response.Write("Exception in Step1:" + ee.ToString());
}
// finally
// {
// con.Close();
// }
try
{
if (step1 == true)
{
// con.Open();
String _view1 = String.Format("Select * from RegisterContender where Name='{2}'", Request.QueryString["Name"].ToString());
SqlCommand cmd1 = new SqlCommand(_view1, con);
SqlDataReader dr = cmd1.ExecuteReader();
while (dr.HasRows)
{
step2 = true;
Response.Write("Step2 fulfilled");
}
if (step2 == false)
{
Response.Write("No Such Contender Exists");
step2 = false;
step1 = false;
}
}
}
catch (Exception eee)
{
Response.Write("Exception in Step2:" + eee.ToString());
}
/*finally
{
con.Close();
}*/
try
{
if (step1 == true && step2 == true)
{
// con.Open();
String _view2 = String.Format("Select * from castVote where VoterLogin='{0}'", Request.QueryString["VoterLogin"].ToString());
SqlCommand cmd2 = new SqlCommand(_view2, con);
SqlDataReader dr = cmd2.ExecuteReader();
while (dr.HasRows)
{
step3 = false;
Response.Write("You have already casted the vote");
return;
}
if (step1 == true && step2 == true)
{
step3 = true;
Response.Write("step 3 fulfilled");
}
}
}
catch (Exception eeee)
{
Response.Write("Exception in step3:" + eeee.ToString());
}
// finally
// {
// con.Close();
// }
try
{
if (step1 == true && step2 == true && step3 == true)
{
// con.Open();
String _view3 = String.Format("Insert into castVote values VoterLogin='{0}' and ContenderName='{2}'", Request.QueryString["VoterLogin"].ToString(), Request.QueryString["ContenderName"].ToString());
SqlCommand cmd3 = new SqlCommand(_view3, con);
SqlDataReader dr = cmd3.ExecuteReader();
Response.Write("Vote Casting Done Successfully");
}
}
catch (Exception eeeee)
{
Response.Write("exception in casting:" + eeeee.ToString());
}
finally
{
step1 = false;
step2 = false;
step3 = false;
con.Close();
}
}
使用的表格是——
create table login_password
(id varchar(200),
_password varchar(200))
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))
当我在本地主机上运行此页面时...使用查询字符串
CastVote/CastVote.aspx?id=naman6064&_password=WW5ghx3p&Name=namit
需要很长时间...然后它说内存不足异常
我做错了什么......我的查询是否正确