protected void btn_Comments_Click(object sender, EventArgs e) { if (Page.IsValid) { ry_Comments Comments = new ry_Comments(); Comments.Name = name.Text; Comments.Email = email.Text; Comments.Comments = comments.Text; Comments.Date = DateTime.Now; Comments.insert(Comments); Response.Redirect("Index.aspx"); } }
public void insertData(ry_Comments obj) { using (SqlConnection sqlConn = new SqlConnection(connString)) { using (SqlCommand cmd = new SqlCommand("usp_insertComments", sqlConn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; sqlConn.Open(); cmd.Parameters.AddWithValue("@Name", obj.Name); cmd.Parameters.AddWithValue("@Email", obj.Email); cmd.Parameters.AddWithValue("@Comments", obj.Comments); cmd.Parameters.AddWithValue("@Date", obj.Date); cmd.ExecuteNonQuery(); } } }