我創建了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();
}
它沒有任何價值......我該怎麼做?
什麼不採取任何價值? – XORcist 2012-08-06 18:57:06
我的意思是,我想從表中檢索數據它不檢索數據... – user1050667 2012-08-06 19:03:08
什麼?什麼顯示空?你可以發佈異常追溯? – XORcist 2012-08-06 19:04:44