I have three tables, appointment, prescription and medication. appointment table have relationship with prescription and prescription have relationship with medication. I already can get the field which is medicationType on medication table and display on the datagridview. From appointment table, jump to prescription and then jump to medication to grab the medicationType field. But now I want to display one more field which is aStatus from appointment table, how to do it? I got this error Only one expression can be specified in the select list when the subquery is not introduced with EXISTS. Help
This image is before I added the aStatus code. But now I want to display aStatus from appointment table too.
The below code is after i added the field aStatus code at the first strCommandText
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 appointmentID, aStatus FROM APPOINTMENT";
SqlCommand cmdAPPOINTMENT = new SqlCommand(strCommandText, myConnect);
string strCommandText2 = "SELECT medicationID FROM PRESCRIPTION WHERE appointmentID IN (" + strCommandText + ")";
SqlCommand cmdPRESCRIPTION = new SqlCommand(strCommandText2, myConnect);
string strCommandText3 = "SELECT medicationType, medicationName FROM MEDICATION WHERE medicationID IN (" + strCommandText2 + ")";
SqlCommand cmdMEDICATION = new SqlCommand(strCommandText3, myConnect);
//string strCommandText3 = "SELECT nFirstName FROM NURSE WHERE nurseID= (" + strCommandText2 + ")";
myConnect.Open();
SqlDataReader readAPPOINTMENT = cmdAPPOINTMENT.ExecuteReader();
readAPPOINTMENT.Close();
SqlDataReader readPRESCRIPTION = cmdPRESCRIPTION.ExecuteReader();
readPRESCRIPTION.Close();
SqlDataReader readMEDICATION = cmdMEDICATION.ExecuteReader();
PrescriptionAdapter = new SqlDataAdapter(strCommandText3, 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;
}