I have a appointment form which will display data in a gridview based on the appointment table. Appointment table have relationship with patient and medicalcentre tables. I wrote the select statement so that patientID will be changed to pFirstName in patient table, and mcID will be changed to mcCentre in the medicalcentre table. Weird thing is pFirstName have no problem, but mcCentre doesn't display after the first row. If I didn't outer join and leave it as mcID, it will display mcID fine on all rows.
MY DATAGRID for appointment form before outer join, display mcID
MY DATAGRID for appointment form after outer join, from mcID changed to mcCentre
MY APPOINTMENT, PATIENT, MEDICALCENTRE TABLE
//MY appointment form after outer join, from mcID changed to mcCentre codes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class member_viewappointment : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
// call BindGridView
bindGridView();
}
}
private void bindGridView()
{
int ID = Convert.ToInt32(Session["ID"].ToString());
//get connection string from web.config
string strConnectionString = ConfigurationManager.ConnectionStrings["sacpConnectionString"].ConnectionString;
SqlConnection myConnect = new SqlConnection(strConnectionString);
string strCommandText = "SELECT aStatus, aDate, aTime, aContact, aHeight, aWeight, med.mcCentre, pat.pFirstName from appointment AS app ";
strCommandText += " LEFT OUTER JOIN MEDICALCENTRE as med on app.appointmentid = med.mcid";
strCommandText += " LEFT OUTER JOIN PATIENT as pat on app.patientid = pat.patientid ";
//strCommandText += " WHERE app.patientid = " + ID.ToString();
try
{
SqlCommand cmd = new SqlCommand(strCommandText, myConnect);
myConnect.Open();
SqlDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
grdViewAppointment.DataSource = dt;
grdViewAppointment.DataBind();
lblResult.Text = "";
reader.Close();
}
catch (SqlException ex)
{
lblResult.Text = "Error:" + ex.Message.ToString();
}
finally
{
myConnect.Close();
}
}
}