PC Review


Reply
Thread Tools Rate Thread

Adding First Row to DataTable causes an error: System.IndexOutOfRangeException

 
 
Brandon
Guest
Posts: n/a
 
      15th Mar 2004
I have a very simple DataTable with two columns. If I remove all of
the rows in the datatable and attempt to add a new row, I receive the
following error:

A first chance exception of type 'System.IndexOutOfRangeException'
occurred in system.windows.forms.dll

Additional information: Index was outside the bounds of the array.


My code to add the new row is below. I am adding a new row for every
object in the array list MyArrayList:

'myDataTable is the dataTable in question

For i As Int16 = 0 To MyArrayList.Count - 1
Dim dr As DataRow = myDataTable.NewRow
dr.Item(0) = MyArrayList.Item(i)
myActivities.Rows.Add(dr)
Next

For some reason I am receiving the error when the ...Rows.Add(dr) is
called for the first row. If I close the program and restart it, I
don't receive the error. Again, this only happens if I first remove
all rows then attempt to add a new row.

I've heard that this may be a bug. Does anyone have any suggestions?

Thanks,

Brandon
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OK with 1.1, System.IndexOutOfRangeException with 2 acb Microsoft Dot NET Framework 0 12th Oct 2005 03:30 PM
System.IndexOutOfRangeException Ratman Microsoft ASP .NET 1 21st Jun 2004 08:18 PM
ListBox && 'System.IndexOutOfRangeException' Dave H Microsoft Dot NET Framework Forms 1 7th May 2004 01:32 PM
System.IndexOutOfRangeException Tylius Microsoft C# .NET 9 18th Jan 2004 11:16 PM
System.IndexOutOfRangeException in XML Reading Juan Galdeano Microsoft C# .NET 0 25th Aug 2003 12:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:43 PM.