我的代码是:当我执行断点时,我正在从数据库中检索数据,它显示列表中的数据,但它也给了我一个错误
public static List<StudentScore> GetAllScore()
{
SqlConnection conn = MyDB.GetConnection();
string selectStm = "SELECT en.CourseID,en.Score,s.StudentID FROM EnrollmentTable en,Student s WHERE en.StudentID = s.StudentID";
SqlCommand command = new SqlCommand(selectStm, conn);
List<StudentScore> aStudentScore = new List<StudentScore>();
try
{
conn.Open();
SqlDataReader reader = command.ExecuteReader();
Console.WriteLine(reader.HasRows.ToString());
while (reader.Read())
{
StudentTable st = new StudentTable();
CourseTable cr = new CourseTable();
Enrollment enr = new Enrollment();
StudentScore score = new StudentScore();
enr.CourseData = cr;
enr.StudentData = st;
//score.EnrollmentData.StudentData.StudentID = reader["StudentID"].ToString();
//score.EnrollmentData.CourseData.CourseID = reader["CourseID"].ToString();
st.StudentID = reader["StudentID"].ToString();
cr.CourseID = reader["CourseID"].ToString();
score.Score = Convert.ToInt32(reader["Score"]);
score.EnrollmentData = enr;
aStudentScore.Add(score);
}
reader.Close();
return aStudentScore;
}
catch (SqlException ex)
{
throw ex;
}
finally
{
conn.Close();
}
}
}
}
它从数据库中获取数据,但显示 mw 这个错误.....对象不能从 DBNull 转换为其他类型,所以这意味着什么,请告诉我如何解决它?