Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我的一个字段值只能成功显示在第一行。下一行没有_C#_Gridview_Outer Join - Fatal编程技术网

C# 我的一个字段值只能成功显示在第一行。下一行没有

C# 我的一个字段值只能成功显示在第一行。下一行没有,c#,gridview,outer-join,C#,Gridview,Outer Join,我有一个约会表单,它将根据约会表在gridview中显示数据。预约表与患者和医疗中心表有关系。我编写了select语句,以便patientID将在patient表中更改为pFirstName,而mcID将在MedicalCenter表中更改为McCenter。奇怪的是pFirstName并没有问题,但McCenter并没有显示在第一行之后。如果我没有外部联接并将其保留为mcID,它将在所有行上显示mcID 外部联接前约会表单的MY DATAGRID,显示mcID 我的DATAGRID预约表在外部

我有一个约会表单,它将根据约会表在gridview中显示数据。预约表与患者和医疗中心表有关系。我编写了select语句,以便patientID将在patient表中更改为pFirstName,而mcID将在MedicalCenter表中更改为McCenter。奇怪的是pFirstName并没有问题,但McCenter并没有显示在第一行之后。如果我没有外部联接并将其保留为mcID,它将在所有行上显示mcID

外部联接前约会表单的MY DATAGRID,显示mcID

我的DATAGRID预约表在外部加入后,从mcID更改为McCenter

我的预约、病人、医疗中心表

//我的预约表在外部加入后,从mcID改为McCenter代码

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

    }
}
您在app.appointmentid=med.mcid上加入MedicalCenter表

这看起来不对。看起来你想加入app.mcid=med.mcid

LEFT OUTER JOIN MEDICALCENTRE as med on app.appointmentid = med.mcid
LEFT OUTER JOIN MEDICALCENTRE as med on app.mcid = med.mcid