我的查询是完美的(我已经在 SQL Server Management Studio 中验证了它)。我的代码很完美,但我仍然收到此语法错误:
'=' 附近的语法不正确。说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。异常详细信息:System.Data.SqlClient.SqlException:“=”附近的语法不正确。
public partial class Temporaryche : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ddlTDept.Items.Clear();
ddlTBranch.Items.Clear();
string connectionString = GlobalVariables.databasePath;
SqlConnection sqlCon = new SqlConnection(connectionString);
string query = "select fac.fac_name, dp.dp_name, br.br_name from STUDENT s, DIVISON dv, BRANCH br, DEPT dp, FACULTY fac, CLASS cls, DEGREE dg where dg.dg_id = cls.dg_id and cls.cls_id = s.cls_id and fac.fac_id = dp.fac_id and dp.dp_id = br.dp_id and br.br_id = dv.br_id and s.dv_id = dv.dv_id and s.prn_no = " + txtSearch.Text;
sqlCon.Open();
SqlCommand cmd = new SqlCommand(query, sqlCon);
SqlDataReader reader = cmd.ExecuteReader();
string facultyName = reader.GetValue(0).ToString();
string deptName = reader.GetValue(1).ToString();
string branchName = reader.GetValue(2).ToString();
ddlTFaculty.SelectedValue = facultyName;
query = "select dp_name from DEPT where fac_id=(select fac_id where fac_name='" + facultyName + "')";
cmd = new SqlCommand(query, sqlCon);
reader = cmd.ExecuteReader();
ddlTDept.Items.Clear();
while (reader.Read())
{
ddlTDept.Items.Add(reader.GetValue(0).ToString());
}
ddlTDept.SelectedValue = deptName;
sqlCon.Close();
}
}