1

I have two sets of dataset and the first dataset contains 20 number of records and the second one contains 21 number of records. When trying to retrieve the second dataset on a grid view, I'm not able to display the records but I can retrieve all the records from first dataset on a gridview. When I'm trying to retrieve the second dataset it is throwing an error like: System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index'

Any suggestion please.

3
  • Post the code you had Commented Dec 30, 2019 at 5:45
  • int a = Int32.Parse(reals); DataTable dummy = new DataTable(); dummy.Columns.Add("OrderNo"); dummy.Columns.Add("InvoiceNo"); for (int i = 0; i < a; i++) { dummy.Rows.Add( id["Results"][i]["OrderNo"].ToString(), id["Results"][i]["InvoiceNo"].ToString()); } GridView1.DataSource = dummy; GridView1.DataBind(); Commented Dec 30, 2019 at 5:51
  • Edit the question then post the code there. Also, Learn how to use code block. Commented Dec 30, 2019 at 5:57

1 Answer 1

1

Getting this error:

System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index'

probably means exactly like it says, that your index is out of range of the dataset. if your index variable i is 22 for example, you will get this error since your datasets don't have a 22nd row. Have you tried debugging and checking whether i is larger than the size of your dataset at any point?

Also, please edit your question and add a code block like the other poster suggested. Without the code it's hard to pinpoint what exactly is going wrong.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.