PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2010 Check whether a DataTable is populated? "Index out of range" error here-VBForums
Results 1 to 3 of 3

Thread: Check whether a DataTable is populated? "Index out of range" error here

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2012
    Posts
    49

    Check whether a DataTable is populated? "Index out of range" error here

    Hi guys, i defined a list of DataTables
    Code:
       Dim PreSubTables As New List(Of DataTable)()
    Then I parse some source files and depending on the data, possibly none of the tables in the list PreSubTables2 might be populated, so it's just an empty list.
    Later on when i refer to the first table in the list , I get "index out of range error"

    Code:
     If (PreSubTables(0).Rows.Count > 0) Then ...
    ' just dealing with the first table:  PreSubtables(0) 
    For ii = 0 To (PreSubTables(0).Rows.Count - 1)
    'print the row
    next
    end if
    on the line where I refer to '.count'...

    I'm just trying to come up with a line that checks whether the(at least the first)Table in the list is populated, before I can print it out or do other things.
    Last edited by SandiegoSSD; May 15th, 2012 at 12:24 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,966

    Re: Check whether a DataTable is populated? "Index out of range" error here

    try this:

    vb Code:
    1. If (PreSubTables1(0) isnot nothing) Then

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2012
    Posts
    49

    Re: Check whether a DataTable is populated? "Index out of range" error here

    Code:
    Thank you Paul.
    This worked for me:
    
    If (PreSubTables.Count > 0) Then
     
                           If (PreSubTables(0).Rows.Count > 0) Then
    '...
    end if
    end if

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width