Ive得到了3个表叫场,CourseCatogory,CourseCourseCatagory。 CourseCourseCatagory是结合表。 我想选择使用结合表链接到特定catogory课程。 这是我第一次使用接线表和JOIN子句,我只是不知道如何去这样做。 它将如果有什么你可以做些什么来帮助我高度赞赏。
public static courseDetails getSelectedCatogory(string Category)
{
courseDetails details = new courseDetails();
using (OleDbConnection connection = getConnection())
{
string query = "SELECT CourseName, Description FROM CourseCourseCategory WHERE Category = @Category JOIN Course ON Course.ID = CourseCourseCategory.CourseID " +
"JOIN CourseCategory ON CourseCategory.ID = CourseCourseCategory.CourseCategoryID";
OleDbCommand command = new OleDbCommand(query, connection);
OleDbParameter pram = new OleDbParameter("@CourseCategory", CourseCategory);
command.Parameters.Add(pram);
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
courseDetails d = new courseDetails();
d.CourseName = reader["CourseName"].ToString();
d.Description = reader["Description"].ToString();
details = d;
}
}
return details;
}