我的应用程序(除了患者编号)然后使用 VisitNumbers 填充访问的下拉列表。每次访问都会为患者生成一个访问编号。当我单击搜索按钮时,获取患者的 visitNumber 并填充我得到的下拉列表并出现错误:
Line 35: {
Line 36: con.Open();
Line 37: SqlDataReader reader = cmd.ExecuteReader();
Line 38:
Line 39: reader = cmd.ExecuteReader();
Stack Trace:
[SqlException (0x80131904): Incorrect syntax near '.'.
Incorrect syntax near 'a'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1753346
HERE IS MY CODE:
public List<string> Get_VisitNumber()
{
List<string> visitnum = new List<string>();
string patient_number = txtPatientNumber.Text;
string connect =
System.Configuration.ConfigurationManager.ConnectionStrings["db_connection"].ToString();
SqlConnection con = new SqlConnection(connect);
string select_statement = "SELECT Visit_Number FROM Patient a ,Visit b"
+ "WHERE a.Patient_Number=b.Patient_Number";
SqlCommand cmd = new SqlCommand(select_statement, con);
cmd.Parameters.AddWithValue("@b.Patient_Number", patient_number);
using (con)
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
reader = cmd.ExecuteReader();
while (reader.Read())
{
if (reader["Patient_Number"] != DBNull.Value)
{
string VID = reader["Visit_Number"].ToString();
visitnum.Add(VID);
}
else
{
Response.Write("<script language=javascript>alert('Patient Number not Found.');</script>");
}
}// end while
} // end using
return visitnum;
}
protected void btn_search_Click(object sender, EventArgs e)
{
DropDownList1.DataSource = Get_VisitNumber();
DropDownList1.DataBind();
}