2013-05-16 41 views
0

我正在寫ASP頁面,其中:學生登錄 - >學生訪問歡迎頁面帶鏈接以顯示他們的註冊課程 - >鏈接頁面顯示課程信息,描述等從ASP/C#網頁中的MS Access數據庫查詢連接表格

我有MS Access數據庫有3個表格:學生(包含學生信息),課程(如課程信息,如ID,描述等)和EnrolledCourses(其中EnrolledCourses是一個聯結表 - 我認爲這是正確的 - 學生和課程代表學生已經註冊的課程)。

我需要顯示他們註冊的課程和課程信息,以便註冊課程中的數據告訴已註冊的課程和來自課程的數據,其中給出了課程的詳細信息。我遇到麻煩,搞清楚查詢將會把這些信息提取出來。這是我到目前爲止:

{    
     //Give the command SQL to execute 
    comm.CommandText = "SELECT Courses.Id, Courses.CourseSubject, Courses.CourseName, Courses.CourseNumber, Courses.CourseDescription FROM Courses, StudentToCourse, Students WHERE Courses.Id = StudentToCourse.Courseid AND Session["id"] = StudentToCourse.Studentid"; 

} 

只是想知道這是否在正確的軌道?我不斷收到編譯錯誤:編譯器錯誤消息:CS1002:;預計

回答

0

你可以試試這個:

comm.CommandText = "SELECT Courses.Id, Courses.CourseSubject, Courses.CourseName, Courses.CourseNumber, Courses.CourseDescription 
FROM Courses, StudentToCourse, Students WHERE Courses.Id = StudentToCourse.Courseid AND StudentToCourse.Studentid = " + Session["id"]; 

但它也有弱點。您應該添加如下參數:

comm.CommandText = "... [email protected]"; 
comm.Parameters.AddWithValue("@studentID", Session["id"]); 

這樣更好/更安全。

相關問題