protected void Button_Click(object sender, EventArgs e) { LinkButton lb = sender as LinkButton; SqlConnection con = null; try { System.Diagnostics.Debug.WriteLine("Statement trying...."); // get the connection to the DB from the web.config connection strings section con = new SqlConnection(ConfigurationManager.ConnectionStrings["WebsiteDBConnectionString"].ConnectionString); // Declare your SQL statement to be executed. // Here, two different SQLs are available depending on the button clicked. string sql = ""; // determine which button was clicked based on the commandName issued if (lb.CommandName.Equals("Like")) { sql = "INSERT INTO UserVotes(username, excuseID, vote) VALUES (@username, @excuseID, 1)"; } else if (lb.CommandName.Equals("Dislike")) { sql = "INSERT INTO UserVotes(username, excuseID, vote) VALUES (@username, @excuseID, -1)"; } int excuseID = Convert.ToInt32(lb.CommandArgument); // open the connection to the DB con.Open(); // Create a command and pass it your various SqlParameters // (here we have one parameter for the PK of the record being updated). SqlCommand cmd = new SqlCommand(sql, con); SqlParameter p = new SqlParameter("excuseID", excuseID); SqlParameter u = new SqlParameter("username", Session["username"]); cmd.Parameters.Add(p); cmd.Parameters.Add(u); // Execute the update query cmd.ExecuteNonQuery(); // close the connection to the DB and re-bind (refresh) the repeater con.Close(); GVsortExcuses.DataBind(); System.Diagnostics.Debug.WriteLine("Statement finished...."); } catch (Exception ex) { // print out error messages to the output window (not the web page) System.Diagnostics.Debug.WriteLine("Exception catched"); System.Diagnostics.Debug.WriteLine(ex.Message); } }