CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Array problem

  1. #1
    Join Date
    Jan 2009
    Posts
    177

    Array problem

    I have the following code:

    Code:
     Dim aaa As New List(Of String())
     Dim dt as Datatable
    How can I loop through the datatable and add into the list?Something like this:

    Code:
    aaa.add(new string() {Row1,Row2,Row3 etc})
    The result should be in one row of the list only.

  2. #2
    Join Date
    Aug 2009
    Location
    NW USA
    Posts
    173

    Re: Array problem

    First: I think you want
    Code:
     Dim aaa As New List(Of String)
    then something like this:
    Code:
    for each r in dt.rows
       aaa.add(r.field) ' where field is a string
    next

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Array problem

    It sounds like the OP is saying that he wants all the rows from the datatable to be in a single string (list row)

    If so then that would require looping through all the rows, appending them to a string then add the completed string to the list.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Aug 2009
    Location
    NW USA
    Posts
    173

    Re: Array problem

    If you want a list of array of string then keep the Dim the same. You will then need to Dim a new String(), somehow set the dimension (maybe ReDim to dt.rows.count) then Add it to aaa. Once you have your single element in aaa then loop through the dt and add it to the first element:
    Code:
    dim i as new integer
    for each r in dt.rows
       aaa(0)(i)=r.field
       i+=1
    next

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured