private void displayVetDetails() { DataView data = (DataView)SqlDataSourceVets.Select(DataSourceSelectArguments.Empty); if (data != null && data.Count > 0) { txtFirstName.Text = data[0]["First_Name"].ToString(); txtLastName.Text = data[0]["Last_Name"].ToString(); txtMobileNo.Text = data[0]["Mobile_no"].ToString(); txtEmail.Text = data[0]["Email"].ToString(); txtAddress.Text = data[0]["Street_Address"].ToString(); txtPostcode.Text = data[0]["Postcode"].ToString(); txtSkills.Text = data[0]["Skills"].ToString(); txtNewID.Text = data[0]["Vet_ID"].ToString(); } }
protected void btnSave_Click(object sender, EventArgs e) { String id = Request.QueryString["id"]; if (id != null && id.Length > 0) { try { SqlDataSourceVets.Update(); displayMessageAlert("Record updated successfully."); } catch (SqlException exc) { String errorMsg = "Error updating record! Please check all fields entered."; displayMessageAlert(errorMsg); } } else { try { String connectionString = ConfigurationManager.ConnectionStrings["Vet_DataConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(connectionString); string query = "INSERT INTO Vet(First_Name, Last_Name, Mobile_no, Email, Street_Address, Postcode, Skills) VALUES (@First_Name, @Last_Name, @Mobile_no, @Email, @Street_Address, @Postcode, @Skills); SELECT SCOPE_IDENTITY();"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@First_Name", txtFirstName.Text); cmd.Parameters.AddWithValue("@Last_Name", txtLastName.Text); cmd.Parameters.AddWithValue("@Mobile_no", txtMobileNo.Text); cmd.Parameters.AddWithValue("@Email", txtEmail.Text); cmd.Parameters.AddWithValue("@Street_Address", txtAddress.Text); cmd.Parameters.AddWithValue("@Postcode", txtPostcode.Text); cmd.Parameters.AddWithValue("@Skills", txtSkills.Text); con.Open(); txtNewID.Text = cmd.ExecuteScalar().ToString(); con.Close(); displayMessageAlert("Record added successfully."); } catch (SqlException exc) { String errorMsg = "Error creating record! Please check all fields entered."; displayMessageAlert(errorMsg); } } }