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

C# 我希望一个表中的值与另一个表中的值同步,c#,winforms,inner-join,sync,C#,Winforms,Inner Join,Sync,我有两张桌子,分别是预约和处方。两者都有关系。在处方表单上,我使用左外部联接代码显示约会表中的aDate字段。问题是它不会与处方表单上的预约表值自动同步。我需要手动转到约会表并输入etc约会id(1)或约会id(2),然后它将显示值。在那之前,我有一个插入函数,我可以使用触发器函数来完成它,但是现在我删除了插入函数alr,所以我想我需要一个新的方法来实现它?救命啊 我的预约表和表格 我的处方表和表格 预约代码 private void appointment_Load(object send

我有两张桌子,分别是预约和处方。两者都有关系。在处方表单上,我使用左外部联接代码显示约会表中的aDate字段。问题是它不会与处方表单上的预约表值自动同步。我需要手动转到约会表并输入etc约会id(1)或约会id(2),然后它将显示值。在那之前,我有一个插入函数,我可以使用触发器函数来完成它,但是现在我删除了插入函数alr,所以我想我需要一个新的方法来实现它?救命啊

我的预约表和表格

我的处方表和表格

预约代码

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;
}
预选码

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

您是否在网格中编辑并输入新约会?更新按钮是如何工作的?对不起,我不记得这个alr了,因为它是6个月前的事了。无论如何谢谢@sasha_gudOh,它已经被编辑过了,我认为这是一个新问题。不要介意。