使用asp.net和sql进行投票
我正在android上制作一款手机投票应用程序。。 为了支持这一点,我在asp.net中有一些页面。 现在我被困在我必须做一个投票的页面上 我想出了这个…使用asp.net和sql进行投票,asp.net,sql,database,voting,Asp.net,Sql,Database,Voting,我正在android上制作一款手机投票应用程序。。 为了支持这一点,我在asp.net中有一些页面。 现在我被困在我必须做一个投票的页面上 我想出了这个… 该计划由三个步骤组成 步骤1检查id和_密码是否正确 步骤2检查表中是否存在竞争者名称 步骤3检查id是否存在于castVote表中,如果不存在,则将其与竞争者名称一起输入 protected void Page_Load(object sender, EventArgs e) { Boolean step1 = false;
该计划由三个步骤组成 步骤1检查id和_密码是否正确 步骤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();
}
}
使用的表格是--
当我在本地主机上运行此页面时。。。使用查询字符串
CastVote/CastVote.aspx?id=naman6064&_password=WW5ghx3p&Name=namit
这需要很长时间。。。然后它说内存不足异常
我做错了什么。。。我的问题对吗你有一个无休止的循环 改变
while (dr.HasRows)
到
无论DataReader是否有行,“HasRows”只会返回true或false,但是“Read”会将SqlDataReader提前到下一条记录。您有一个无休止的循环 改变
while (dr.HasRows)
到
无论DataReader是否有行,“HasRows”只会返回true或false,但是“Read”会将SqlDataReader提前到下一条记录。谢谢,但现在它显示了一个异常。步骤1在步骤2中实现了异常:System.FormatException:索引(基于零)必须大于或等于零,并且小于参数列表@Wizethanks的大小,但它现在显示异常。步骤1在步骤2中实现了异常:System.FormatException:索引(基于零)必须大于或等于零且小于参数列表@Wize的大小
while (dr.Read())