Create tabke like
id int
likedis bit
productid int
userid varchar(150)
make unique constraints on (productid,userid)
Create stored procedure like
ALTER PROCEDURE [dbo].[inslike]
@aid int,
@userid varchar(150)
as
BEGIN
begin try
BEGIN TRANSACTION
insert into tbllike (likedis,productid,userid) values(1,@aid,@userid);
update tblProduct set like1=like1+1 where ID=@aid;
Commit
end try
begin catch
ROLLBACK
end catch
END
on like buttonclick
SqlCommand cmd = new SqlCommand();
cmd.Connection = GetConnection();
cmd.CommandText = "inslike";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@aid", int.Parse(e.CommandArgument.ToString()));
cmd.Parameters.AddWithValue("@userid", Session["userid"].ToString());
cmd.ExecuteNonQuery();
cmd.Connection.Close();
getData();