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