我创建了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