locked
System.IndexOutOfRangeException: Silver RRS feed

  • Question

  • User-1112107407 posted

    in my table "Show_Time" both "Golden" and "Silver" fields are there. Now Check my code,

    int remain_sil = 0;
    
    SqlDataReader dr4 = db.ExRdr("select Golden from Show_Time");
                while (dr4.Read())
                {
                    remain_gold = Int32.Parse(dr4["Golden"].ToString());
                    remain_sil = Int32.Parse(dr4["Silver"].ToString());
                }
                dr4.Close();

    Am Damn Sure "Silver" filed is in my table, then too it shows the error on silver. But Not showing in "Golden". The error is,

     System.IndexOutOfRangeException: Silver

     

    my stack trace is below,

                              

    [IndexOutOfRangeException: Silver]
       System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) +5271062
       System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) +61
       System.Data.SqlClient.SqlDataReader.get_Item(String name) +15
       User_Confirm_Cancel.ImageButton1_Click(Object sender, ImageClickEventArgs e) in m:\MCA III Websites\Multiplex_Sample2\User\Confirm_Cancel.aspx.cs:68
       System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +115
       System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +124
       System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
    

                     

                Why it shows this error, because i think IndexOutOfBoundException is when the filed is not in table!

    Can any one give solution?

    Tuesday, October 22, 2013 2:21 PM

Answers

  • User2103319870 posted

    You are selecting only "Golden" field from your table and thats the reason you are getting exception.

    Try changing your select query like given below

    SqlDataReader dr4 = db.ExRdr("select Golden,Silver from Show_Time");

    OR

    SqlDataReader dr4 = db.ExRdr("select * from Show_Time");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 22, 2013 2:33 PM

All replies

  • User2103319870 posted

    You are selecting only "Golden" field from your table and thats the reason you are getting exception.

    Try changing your select query like given below

    SqlDataReader dr4 = db.ExRdr("select Golden,Silver from Show_Time");

    OR

    SqlDataReader dr4 = db.ExRdr("select * from Show_Time");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 22, 2013 2:33 PM
  • User-1112107407 posted

    You are selecting only "Golden" field from your table and thats the reason you are getting exception

    Thanks a lot,,it was my mistake only:) thanks once again

    Tuesday, October 22, 2013 10:30 PM