【发布时间】:2014-02-10 23:31:30
【问题描述】:
我有两张表,即预约表和医疗中心,它们使用 mcID 相互关联。现在我的预约表格,我使用外连接在医疗中心表中显示 mcCentre,而不是在 gridview 中显示 mcID。您在我的表格中看到,所有医疗中心(mcCentre)都显示在网格视图中。但我只想显示黄和梁家庭诊所的记录,因为我想匹配文本框中的文本,即黄和梁家庭诊所。这意味着水医院文本在文本框中,我只希望该医院记录出现在网格视图中。文本框名称为 txtCentre。
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, convert(varchar, aDate, 103) AS aDate, aTime, aStatus, aContact, aHeight, aWeight, patientID, mcID, nurseID FROM APPOINTMENT";
string strCommandText = "SELECT appointmentID, convert(varchar, aDate, 103) AS aDate, aTime, aStatus, aContact, aHeight, aWeight, pat.pFirstName, pat.pLastName, cen.mcCentre, nur.nUsername FROM APPOINTMENT AS app";
strCommandText += " LEFT OUTER JOIN PATIENT as pat on app.patientid = pat.patientid";
strCommandText += " LEFT OUTER JOIN MEDICALCENTRE as cen on app.mcid = cen.mcid";
strCommandText += " LEFT OUTER JOIN NURSE as nur on app.nurseid = nur.nurseid";
//strCommandText += " LEFT OUTER JOIN NURSE as nur on app.nurseid = nur.nurseid";
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;
}
【问题讨论】:
标签: c# windows datagridview textbox record