患者番号を除く私のアプリケーションは、訪問のドロップダウンに VisitNumbers.A を入力します。訪問番号は、訪問ごとに患者に対して生成されます。検索ボタンをクリックすると、患者の 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();
}