MsDotNet raja

MsDotNet raja

  • NA
  • 10
  • 2.5k

button click in repeater increments the value in database

Jan 2 2016 12:26 AM
Hi, I have a column called Likes in my db, and in repeater i have a button, if a user clicks on the button the value in db should increase by +1 on every click and the button should display the number of likes in count(as 32 likes). 
 
asp code:
 
<asp:Button ID="btnlike" CommandName="like" style="height:40px;width:70px" runat="server" Font-Bold="true" BorderColor="Blue" Text="Like" />
 
 
C# code:
 
protected void rptCustomers_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
using (MySqlConnection con = new MySqlConnection(connString))
{
using (MySqlCommand cmd = new MySqlCommand("UPDATE articles SET Likes = Likes+1 WHERE Pid=" + Pid, con))
{
using (con)
{
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
 
Please correct my code, thanx in advance. 
 

Answers (4)