IndexOutOfRangeException - Index was outside the bounds of the array.

D

Doug McCormick

We are encountering an extremely odd issue. We process incoming files for
customers and output text files to produce printed material. Then an XML
file
containing the fields of the original file along with all fields necessary
to
produce the output text files are saved as an XML file. If an individual's
printed material is destroyed in the process of fulfillment, we must
reproduce the output for them. We do this by reading the XML file back into
a
dataset and re-outputting the text files. The XML file (and hence the
datatable in the dataset) have a LOT of fields/columns (some have over
1000).

We discovered that if a column is added to the datatable at the end of the
columns collection, AND is later referred to in a SELECT clause to return a
row collection, AND then large amounts of columns are removed and then added
back into the columns collection, the following error is thrown:

System.IndexOutOfRangeException - Index was outside the bounds of the array.

We also discovered that if we added the column referred to in the SELECT
clause at the BEGINNING of the columns collection (which was not easy) the
error did NOT occur. However, this is simply side-stepping the bigger issue.

I have sample code that will duplicate this behavior, but that and the XML
is too long to post. Is there some way to post this code and XML?

This is running on .NET 1.1 framework. Any light that could be shed on this
issue would be greatly appreciated.

Thank you.
 
L

Luke Zhang [MSFT]

Hello,

I downloaded your code and run it on my computer. But I failed to reproduce
the problem, the program runs smoothly withtout the exception after I click
the the button. Did I missed something? Have you tried the same code on
more computer?

Regards,

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
D

Doug McCormick

Hello,

I was instructed by Microsoft to invoke the AcceptChanges method on the
datatable after adding/removing columns. This has corrected the issue.

Thanks!
Doug
 
K

Kevin Yu [MSFT]

Hi Doug,

It was nice to hear that you have had the problem resolved. Thanks for
sharing your experience with all the people here. If you have any
questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top