You are on page 1of 1

private void Vota(string VotaId)

{
//Vendosja e votes
//Lidhja me DB
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStr
ings["ConnectionString"].ConnectionString);
//sql komanda per inkrementim te votes ne baze te ID
SqlCommand cmd = new SqlCommand("UPDATE Votes SET NumVotes = NumVotes+1 WHER
E VotaId=@VotaId", conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@VotaId", VotaId);
using (conn)
{
//Lidhja me DB
conn.Open();
//ekzekuton querin
cmd.ExecuteNonQuery();
}
//Regjistrimi i votuesve qe mos te kene mundsi me votua prap'
//Lidhja me DB
conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Connecti
onString"].ConnectionString);
//sql komanda me e vnua usernamein n'tabelen e votuesve
cmd = new SqlCommand("INSERT INTO Voted(UserName) VALUES (@UserName)", conn)
;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@UserName", Page.User.Identity.Name);
using (conn)
{
//Lidhja me DB
conn.Open();
//Ekzekutojm querin
cmd.ExecuteNonQuery();
}
//e reloadojm nderfaqen
Response.Redirect("nderfaqja.cs");
}
protected void btnA_Click(object sender, EventArgs e)
{
//Thirr metoden Vota edhe ja shoqron opsionin A
Vota("A");
}
protected void btnB_Click(object sender, EventArgs e)
{
//njajt thirrim dhe shoqrojm n'rast te zgjedhjes se opsionit B
Vota("B");
}

You might also like