0

I have two tables which is appointment and prescription. Both have relationship with each other. On prescription form, I use left outer join code to display the aDate field from appointment table. The problem is it won't auto sync with appointment table values on the prescription form. I need to go to the appointment table manually and key in etc appointment id (1) or appointment id (2), then it will display the values. Before that, I have a insert function, and i can use the trigger function to do it, but now i removed that insert function alr, so I need a new method for this i guess? HELP.

MY APPOINTMENT TABLE AND FORM enter image description here

MY PRESCRIPTION TABLE AND FORM enter image description here

APPOINTMENT CODE

private void appointment_Load(object sender, EventArgs e)
{
    LoadAppointmentRecords();
    AnimateWindow(this.Handle, 1000, AnimateWindowFlags.AW_CENTER);
}

private void LoadAppointmentRecords()
{

    //retrieve connection information info from App.config
    string strConnectionString = ConfigurationManager.ConnectionStrings["SACPConnection"].ConnectionString;
    //STEP 1: Create connection
    SqlConnection myConnect = new SqlConnection(strConnectionString);
    //STEP 2: Create command
    string strCommandText = "SELECT appointmentID, aDate, aTime, aStatus, aContact, aHeight, aWeight, patientID, mcID, nurseID FROM APPOINTMENT";


    AppointmentAdapter = new SqlDataAdapter(strCommandText, myConnect);

    //command builder generates Select, update, delete and insert SQL
    // statements for MedicalCentreAdapter
    SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(AppointmentAdapter);
    // Empty Employee Table first
    Appointment.Clear();
    // Fill Employee Table with data retrieved by data adapter
    // using SELECT statement
    AppointmentAdapter.Fill(Appointment);

    // if there are records, bind to Grid view & display
    if (Appointment.Rows.Count > 0)
        grdApp.DataSource = Appointment;
}

PRESCRIOPTION CODE

private void prescription_Load(object sender, EventArgs e)
{
    LoadPrescriptionRecords();
}

private void LoadPrescriptionRecords()
{
    //retrieve connection information info from App.config
    string strConnectionString = ConfigurationManager.ConnectionStrings["SACPConnection"].ConnectionString;
    //STEP 1: Create connection
    SqlConnection myConnect = new SqlConnection(strConnectionString);
    //STEP 2: Create command

    string strCommandText = "SELECT prescriptionID, app.aDate FROM PRESCRIPTION AS pres ";
    strCommandText += "LEFT OUTER JOIN appointment as app on pres.appointmentid = app.appointmentid ";
    myConnect.Open();

    PrescriptionAdapter = new SqlDataAdapter(strCommandText, myConnect);

    //readMEDICATION.Close();
    myConnect.Close();

    //command builder generates Select, update, delete and insert SQL
    // statements for MedicalCentreAdapter
    SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(PrescriptionAdapter);
    // Empty Employee Table first
    Prescription.Clear();
    // Fill Employee Table with data retrieved by data adapter
    // using SELECT statement
    PrescriptionAdapter.Fill(Prescription);

    // if there are records, bind to Grid view & display
    if (Prescription.Rows.Count > 0)
        grdPrescription.DataSource = Prescription;     
}
default locale
  • 11,849
  • 13
  • 52
  • 59
Pony
  • 381
  • 3
  • 9
  • 40

0 Answers0