locked
System.IndexOutOfRangeException RRS feed

  • Question

  • User-239141908 posted
    using (SqlCommand sqlCmd = new SqlCommand("select orderID,Description as addressType from udf_getAddressTypeInfoOthers(" + RetrievedValue + ")", cnn))
                    {
                        cnn.Open();
                        SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
                        DataSet ds = new DataSet();
                        da.Fill(ds);
    
    
                        sqlCmd.CommandType = System.Data.CommandType.Text;
    
    
                        SqlDataReader reader = sqlCmd.ExecuteReader();
    
                        
                        while (reader.Read())
                        {
    
                            
                                ListItem item = new ListItem();
                                item.Text = reader["Description"].ToString();
                                item.Value = reader["orderID"].ToString();
                                DdlAddType.Items.Add(item.Text);
                                
    
                            
                        }
                        cnn.Close();
                    }

    System.IndexOutOfRangeException

    Wednesday, July 31, 2019 12:28 PM

Answers

  • User753101303 posted

    Hi,

    It always means the index is not valid. Here this is likely because your SQL statement is using a column alias so it should be reader["addressType"] (or you don't use an alias for this column ?)

    Edit: not directly related but have a look for "SQL parameters" which is better than using string concatenation.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 31, 2019 12:36 PM

All replies

  • User-239141908 posted

    How Can I solve above binding problem

    Wednesday, July 31, 2019 12:29 PM
  • User753101303 posted

    Hi,

    It always means the index is not valid. Here this is likely because your SQL statement is using a column alias so it should be reader["addressType"] (or you don't use an alias for this column ?)

    Edit: not directly related but have a look for "SQL parameters" which is better than using string concatenation.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 31, 2019 12:36 PM
  • User-239141908 posted

    Hi,

    It always means the index is not valid. Here this is likely because your SQL statement is using a column alias so it should be reader["addressType"] (or you don't use an alias for this column ?)

    Thank you PatriceSc

    Wednesday, July 31, 2019 1:20 PM