1

私はアンドロイドでモバイル投票のアプリを作っています..私はasp.netにいくつかのページがあることをサポートしています。今、私は投票が行われるページを作成しなければならないところで立ち往生しています...

私はこれを思いつきました...
プログラムは3つのステップで構成されています..

ステップ 1 では、id と _password が正しいか間違っているかをチェックします。

ステップ 2 は、候補名がテーブルに存在するかどうかを確認します。

ステップ 3 では、id が castVote テーブルに存在するかどうかを確認します。存在しない場合は、contenderName で入力します...

 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

時間がかかります...その後、メモリ不足の例外が表示されます

私の何が間違っているのか...私のクエリは正しいですか

4

1 に答える 1