0
我有一个与NURSE表,MEDICALCENTRE表和PATIENT表有关系的APPOINTMENT表。在下面附加的第一个图像是我的表单,它在数据网格视图中显示来自APPOINTMENT表的所有数据。我想要做的是将patientID,mcID和nurseID的字段名称更改为其他表中的其他字段。我希望patientID显示为PATIENT表中存在的pFirstName。 mcID显示为存在于MEDICALCENTRE表中的mcCentre。并且nurseID显示为NURSE表中存在的nFirstName。以下是我的page_five表单代码。我应该在选择声明中更改什么才能实现我想要显示的内容?如何更改窗体中某些表的字段以显示其他表中的其他字段?
//我的约会表单代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace GRP_02_03_SACP
{
public partial class appointment : Form
{
// Data Table to store employee data
DataTable Appointment = new DataTable();
// Keeps track of which row in Gridview
// is selected
DataGridViewRow currentRow = null;
SqlDataAdapter AppointmentAdapter;
public appointment()
{
InitializeComponent();
}
private void appointment_Load(object sender, EventArgs e)
{
LoadMedicalCentreRecords();
}
private void LoadMedicalCentreRecords()
{
//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 btnUpdate_Click(object sender, EventArgs e)
{
int modifiedRows = 0;
// Get changes
DataTable UpdatedTable = Appointment.GetChanges();
if (UpdatedTable != null)
{
// there are changes
// Write modified data to database
modifiedRows = AppointmentAdapter.Update(UpdatedTable);
// accept changes
Appointment.AcceptChanges();
}
else
MessageBox.Show("there are no changes to update");
if (modifiedRows > 0)
{
MessageBox.Show("There are " + modifiedRows + " records updated");
LoadMedicalCentreRecords();
}
}
}
}
约会表单 委任表 护士表 MEDICALCENTRE表 患者台上
谢谢,但我现在不能使用更新功能来改变我的所有字段的值的值。这个错误(动态SQL生成不支持针对多个基表)。@SaUce – Pony
我为此创建了一个新线程http://stackoverflow.com/questions/21201170/i-changed-some-of-my-fields-to -display-as-other-fields-in-other-table-and-now-i @SaUce – Pony