0
        string username1 = Session["SessionName"] != null ? Session["SessionName"].ToString() : null;

        if (IsPostBack != true)
        { 
            string constr4 = ConfigurationManager.ConnectionStrings["IntranetDB"].ConnectionString;
        SqlConnection con4 = new SqlConnection(constr4);
        con4.Open();
        SqlDataAdapter adpt4 = new SqlDataAdapter("select * from ReleaseNotes", con4);
        DataTable dt4 = new DataTable();
        adpt4.Fill(dt4);

        List<String> RteReleaseNotes3 = new List<String>();
        RteReleaseNotes3 = dt4.AsEnumerable()
                    .Select(r => r.Field<string>("contentarea"))
                    .ToList();
        rteReleaseNotes.Value = RteReleaseNotes3[0];//set value for RTE from DB. 

            string constr5 = ConfigurationManager.ConnectionStrings["IntranetDB"].ConnectionString;
            SqlConnection con5 = new SqlConnection(constr5);
            con5.Open();
            SqlDataAdapter adpt5 = new SqlDataAdapter("select * from Links", con5);
            DataTable dt5 = new DataTable();
            adpt5.Fill(dt5);

            List<String> quickLinks3 = new List<String>();
            quickLinks3 = dt5.AsEnumerable()
                        .Select(r => r.Field<string>("quicklinks"))
                        .ToList();
            quickLinks.Value = quickLinks3[0];//set value for RTE from DB. 


        }

I keep getting the error on the last line: quickLinks.Value = quickLinks3[0];//set value for RTE from DB. I'm helping a company with their intranet. There are multiple pages, and sql servers, and im a noob to this because this is just an internship. I'm to use existing code to make something that is already pretty similar to whats been done, but I keep getting the error:

An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code Additional information: Index was out of range. Must be non-negative and less than the size of the collection.

I'm using a sql database(with no data in it yet) if that helps

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • 2
    you're accessing an array's index that doesnt exist. Use debugger in visual studio to see where your exception is thrown. If quickLinks3 is null, you will get that exception. – Jawad Jun 09 '20 at 17:29
  • to help you out, use this, `quickLinks.Value = quickLinks3 != null && quickLinks.Count > 0 ? quickLinks3.First() : string.empty;` – Jawad Jun 09 '20 at 17:34
  • `ToList` never returns `null`. We're not talking about NRE here. `quickLinks3` is empty. – madreflection Jun 09 '20 at 17:37

0 Answers0