Thursday, 24 January 2013

code for how to count votes regarding their symbols using asp.net c#

    
    protected void BtnVote_Click(object sender, EventArgs e)
    {
        if (Rbtbjp.Checked == true || Rbtcongress.Checked == true || RbtTDP.Checked == true)
        {
            string value;
            string strr = "select partyname from votescount where partyname like '%" + name + "%'";
            NpgsqlDataAdapter da = new NpgsqlDataAdapter(strr, con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            if (ds.Tables[0].Rows.Count == 0)
            {
                value = "";
            }
            else
            {
                value = ds.Tables[0].Rows[0][0].ToString();
            }

            if (value == name)
            {
                string qrr = "select vote from votescount where partyname ='" + name + "'";
                con.Open();
                NpgsqlDataAdapter da1 = new NpgsqlDataAdapter(qrr, con);
                DataSet ds1 = new DataSet();
                da1.Fill(ds1);
                count = Convert.ToInt32(ds1.Tables[0].Rows[0][0].ToString());
                count = count + 1;
                string str = "update votescount set partyname='" + name + "',vote='" + count + "' where partyname ='" + name + "' ";

                NpgsqlCommand cmd = new NpgsqlCommand(str, con);
                cmd.ExecuteNonQuery();
                con.Close();
                Response.Write("<script>alert('Inserted Successfully........')</script>");
                gridfill();
            }
            else
            {
                count = 1;
                string str = "Insert into votescount(partyname,vote,partysymbol) values('" + name + "','" + count + "','" + imgurl + "')";
                con.Open();
                NpgsqlCommand cmd = new NpgsqlCommand(str, con);
                cmd.ExecuteNonQuery();
                con.Close();
                Response.Write("<script>alert('Inserted Successfully........')</script>");
                gridfill();
            }
            Btnclear_Click(sender, e);
        }
        else
        {
            Response.Write("<script>alert('plz select party........')</script>");
        }
    }





No comments:

Post a Comment