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();
}
値を取りません....どうすればいいですか?