0

我正在编写一个 ASP 页面,其中:学生登录 -> 学生到达欢迎页面,带有链接以向他们展示他们已注册的课程 -> 链接页面显示课程信息、描述等。

我的 MS Access 数据库有 3 个表:学生(包含学生信息)、课程(课程信息,如 ID、描述等)和 EnrolledCourses(其中 EnrolledCourses 是一个连接表 - 我认为这是正确的术语 -学生和课程代表学生已注册的课程)。

我需要显示他们注册了哪些课程和课程信息,因此来自 EnrolledCourses 的数据告诉了已注册的课程和来自 Courses 的数据,这些数据提供了课程的详细信息。我在弄清楚查询将是什么来提取该信息时遇到了麻烦。到目前为止,这是我想出的:

{               
        //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:;预期的

4

1 回答 1

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 = "... StudentToCourse.Studentid=@studentID";
comm.Parameters.AddWithValue("@studentID", Session["id"]);

那更好/更安全。

于 2013-05-16T02:19:33.947 回答