public List<Evaluation> GetAllEvaluations()
{
string query = "SELECT * FROM Evaluation";
try
{
SqlCommand.CommandText = query;
SqlConnection.Open();
IDataReader data = SqlCommand.ExecuteReader();
List<Evaluation> evaluations = new List<Evaluation>();
while (data.Read())
{
Evaluation anEvaluation = new Evaluation
{
Id = Convert.ToInt16(data["Id"]),
Grade = data["Grade"].ToString()
};
evaluations.Add(anEvaluation);
}
return evaluations;
}
finally
{
if (SqlConnection != null && SqlConnection.State == ConnectionState.Open)
{
SqlConnection.Close();
}
}
未处理的类型&#39; System.IndexOutOfRangeException&#39;发生在System.Data.dll
中其他信息:成绩
答案 0 :(得分:0)
您的变量data
未定义Id
或Grade
...因此它返回“超出范围”,因为它不包含在您的变量中。尝试调试代码并找出原因。