在对访问数据库执行此查询时,我收到了缺少的运算符语法错误。它在我使用SQL服务器时有效。任何帮助表示赞赏:
String sql = "Select tblStudent.StudentID,tblStudent.studentFirstName,tblStudent.studentLastName,tblSchool.schoolName,tblAgents.agentFirstName,tblAgents.agentLastName,tblAgents.agentID,tblGuardians.guardianFirstName,tblGuardians.guardianLastName,tblGuardians.guardianID,tblConsultants.consultantFirstName,tblConsultants.consultantLastName,tblConsultants.consultantID " +
"FROM (tblStudent LEFT JOIN tblSchool " +
"ON (tblStudent.schoolID = tblSchool.schoolID)) " +
"LEFT JOIN tblAgents " +
"ON (tblStudent.agentID = tblAgents.agentID) " +
"LEFT JOIN tblGuardians " +
"ON (tblStudent.guardianID = tblGuardians.guardianID) " +
"LEFT JOIN tblConsultants " +
"ON (tblStudent.consultantID = tblConsultants.consultantID) " +
"WHERE tblStudent.StudentID=@studentID";
m_dbConnection.Open();
using (OleDbCommand cmd = new OleDbCommand(sql, m_dbConnection))
{
cmd.Parameters.AddWithValue("@StudentID", studentID);
using (OleDbDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
lblSchool.Text = Convert.ToString(dr["schoolName"]);
lblStudentFirstName.Text = Convert.ToString(dr["studentFirstName"]);
lblStudentLastName.Text = Convert.ToString(dr["studentLastName"]);
lblAgentFirstName.Text = Convert.ToString(dr["agentFirstName"]);
lblAgentLastName.Text = Convert.ToString(dr["agentLastName"]);
lblAgentID.Text = Convert.ToString(dr["agentID"]);
lblGuardianFirstName.Text = Convert.ToString(dr["guardianFirstName"]);
lblGuardianLastName.Text = Convert.ToString(dr["guardianLastName"]);
lblGuardianID.Text = Convert.ToString(dr["guardianID"]);
lblConsultantFirstName.Text = Convert.ToString(dr["consultantFirstName"]);
lblConsultantLastName.Text = Convert.ToString(dr["consultantLastName"]);
lblConsultantID.Text = Convert.ToString(dr["consultantID"]);
lblID.Text = studentID;
但如果我这样做:它有效:
String sql2 = "Select tblStudent.StudentID,tblStudent.studentFirstName,tblStudent.studentLastName,tblSchool.schoolName,tblAgents.agentFirstName,tblAgents.agentLastName,tblAgents.agentID " +
"FROM (tblStudent LEFT JOIN tblSchool " +
"ON (tblStudent.schoolID = tblSchool.schoolID)) " +
"LEFT JOIN tblAgents " +
"ON (tblStudent.agentID = tblAgents.agentID) " +
"WHERE tblStudent.StudentID=@studentID";
答案是这样的。我不得不使用多个括号
String sql = "Select tblStudent.StudentID,tblStudent.studentFirstName,tblStudent.studentLastName,tblSchool.schoolName,tblAgents.agentFirstName,tblAgents.agentLastName,tblAgents.agentID,tblGuardians.guardianFirstName,tblGuardians.guardianLastName,tblGuardians.guardianID,tblConsultants.consultantFirstName,tblConsultants.consultantLastName,tblConsultants.consultantID " +
"FROM ((((tblStudent LEFT JOIN tblSchool " +
"ON tblStudent.schoolID = tblSchool.schoolID) " +
"LEFT JOIN tblAgents " +
"ON tblStudent.agentID = tblAgents.agentID) " +
"LEFT JOIN tblGuardians " +
"ON tblStudent.guardianID = tblGuardians.guardianID) " +
"LEFT JOIN tblConsultants " +
"ON tblStudent.consultantID = tblConsultants.consultantID) " +
"WHERE tblStudent.StudentID=@studentID";