我在点击进入另一个桌面用户界面的子菜单时收到此错误

时间:2014-09-06 23:16:21

标签: c# asp.net-mvc-5 desktop-application

    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

其他信息:成绩

1 个答案:

答案 0 :(得分:0)

您的变量data未定义IdGrade ...因此它返回“超出范围”,因为它不包含在您的变量中。尝试调试代码并找出原因。