locked
An exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll but was not handled in user code RRS feed

  • Question

  • User364480375 posted
     public IEnumerable<PraptraEntity> Get(string month, string year)
            {
                SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
                SqlCommand cm = new SqlCommand();
                List<PraptraEntity> model = new List<PraptraEntity>();
                cm.Connection = cn;
                cm.Connection.Open();
                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "spGetpraptra104ByMonth";
                cm.Parameters.AddWithValue("@month", month);
                cm.Parameters.AddWithValue("@year", year);
                SqlDataReader rdr = cm.ExecuteReader();
                while (rdr.Read())
                {
                    PraptraEntity praptraEntity = new PraptraEntity();
                    //praptraEntity.pid = Convert.ToInt32(rdr["pid"]);
                    praptraEntity.r_date = Convert.ToDateTime(rdr["r_date"]);// getting error
                    praptraEntity.r_month = Convert.ToString(rdr["r_month"]);
                    praptraEntity.DistrictName = Convert.ToString(rdr["DistrictHName"]);
                    praptraEntity.cell_02 = Convert.ToString(rdr["cell_02"]);
                    praptraEntity.cell_03 = Convert.ToDecimal(rdr["cell_03"]);
                    praptraEntity.cell_04 = Convert.ToDecimal(rdr["cell_04"]);
                    praptraEntity.cell_05 = Convert.ToDecimal(rdr["cell_05"]);
                    praptraEntity.cell_06 = Convert.ToDecimal(rdr["cell_06"]);
                    praptraEntity.cell_07 = Convert.ToDecimal(rdr["cell_07"]);
                    praptraEntity.cell_08 = Convert.ToDecimal(rdr["cell_08"]);
                    praptraEntity.cell_09 = Convert.ToDecimal(rdr["cell_09"]);
                    praptraEntity.cell_10 = Convert.ToDecimal(rdr["cell_10"]);
                    praptraEntity.cell_11 = Convert.ToString(rdr["cell_11"]);               
                    model.Add(praptraEntity);
                }
                rdr.Close();
                cm.Connection.Close();
                return model;
            }            

    Getting error  in this line kindly suggest: praptraEntity.r_date = Convert.ToDateTime(rdr["r_date"]);// getting error



    Thursday, August 30, 2018 6:50 AM

All replies

  • User-1716253493 posted

    seem like r_date column is not exist in the sp results

    Thursday, August 30, 2018 7:08 AM
  • User-1034726716 posted

    can we see your Store procedure?

    Thursday, August 30, 2018 10:56 PM