我希望一个表中的值与另一个表值同步

时间:2014-01-27 02:03:24

标签: c# winforms inner-join sync

我有两张桌子,是预约和处方。两者都有相互关系。在处方表格上,我使用左外连接代码来显示约会表中的aDate字段。问题是它不会与处方表上的约会表值自动同步。我需要手动转到约会表并输入等待约会ID(1)或约会ID(2),然后它将显示值。在此之前,我有一个插入函数,我可以使用触发器函数来做,但现在我删除了插入函数alr,所以我需要一个新的方法,我猜? HELP。

我的任命表和表格 enter image description here

我的处方表和表格 enter image description here

任命代码

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;
}

PRESCIIOPTION 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;     
}

0 个答案:

没有答案