【发布时间】:2014-02-25 05:46:31
【问题描述】:
我有一个约会表格,它将根据约会表在网格视图中显示数据。我编写了 select 语句,以便将患者表中的患者 ID 更改为 pFirstName,并将医疗中心表中的 mcID 更改为 mcCentre。有一个 WHERE 查询,因为我只想显示仅属于当前用户登录的约会/行。当我调试时,我得到了这个错误 Ambiguous column name patientID。
我的查看预约表
我的 3 张预约表、医疗中心和患者。
我的查看预约表格代码:
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 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();
}
}
}
【问题讨论】:
标签: c# gridview outer-join