protected void Page_Load(object sender, EventArgs e) { Student student; // Set the content type Response.ContentType = "text/plain"; Response.ContentEncoding = Encoding.UTF8; // POSTed data student = new Student() { Id = int.Parse(Request.Form["id"]), Name = Request.Form["name"], Age = int.Parse(Request.Form["age"]) }; if (UpdateStudentInDB(student)) { Response.Write(OutputValues(student)); } else { // Return error string as "error : some error message" Response.Write(OutputError("failed to update student with primary key {0}", student.Id)); } } private bool UpdateStudentInDB(Student student) { SqlConnection connection; SqlCommand command; int recordsUpdated; bool result = false; connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString); command = new SqlCommand("UPDATE Student Name=@Name, Age=@Age WHERE Id=@Id", connection); command.Parameters.AddWithValue("@Id", student.Id); command.Parameters.AddWithValue("@Name", student.Name); command.Parameters.AddWithValue("@Age", student.Age); using (connection) { connection.Open(); recordsUpdated = command.ExecuteNonQuery(); if (recordsUpdated > 0) { result = true; } } return result; }