我创建了 3 个类,然后这 3 个类的对象在另一个类中创建。现在我想从数据库中读取数据。我的代码是:我正在从数据库中检索数据并从组合框中调用。
SqlConnection conn = MyDB.GetConnection();
string selectStm = "SELECT c.CourseID,en.Score,s.StudentID FROM EnrollmentTable en,Course c,Student s WHERE en.StudentID = s.StudentID AND en.CourseID = c.CourseID";
SqlCommand command = new SqlCommand(selectStm, conn);
//command.Parameters.AddWithValue("@StudentID", StudentID);
List<StudentScore> aStudentScore = new List<StudentScore>();
StudentScore score = null;
try
{
conn.Open();
SqlDataReader reader = command.ExecuteReader();
Enrollment enr = new Enrollment();
while (reader.Read())
{
score = new StudentScore();
score.EnrollmentData.StudentData.StudentID = reader["StudentID"].ToString();//Here is the problem.
score.EnrollmentData.CourseData.CourseID = reader["CourseID"].ToString();//Here is the problem.
score.Score = Convert.ToInt32(reader["Score"]);
aStudentScore.Add(score);
}
reader.Close();
return aStudentScore;
}
catch (SqlException ex)
{
throw ex;
}
finally
{
conn.Close();
}
它没有任何价值....我该怎么做?