Results 1 to 2 of 2

Thread: 2D array

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    42

    2D array

    Table
    -----
    FileName EmailAddress
    (0,0) File A (1,0) [email protected]
    (0,1) File A (1,1) [email protected]
    (0,2) File B (1,2) [email protected]
    (0,3) File B (1,3) [email protected]
    (0,4) File C (1,4) [email protected]
    (0,5) File C (1,5) [email protected]

    Hi all, the table above shows the example of my database.
    I have managed to convert the recordset from access table to 2D array.
    My aim to iterate the array, so if the file name is File A, it will retrieve all the email address which belongs to File A.

    I've been trying to think of codes, but i'm bad with 2D arrays, can someone guide me or provide me with examples to achieve my desired results?

    Many thanks.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: 2D array

    You'd be better of using ADO.NET to populate a DataTable and then using that to manipulate the data. The situations where a 2D array is appropriate are few and this is not one of them. They should really only be used for genuine matrices, i.e. where each element is a sibling. They should NOT be used to represent data where each "row" is a record. There are lots of other data structures that are more appropriate for that, like the DataTable. Check out the following example. I'm creating a DataTable manually but you would get the same data from Access using ADO.NET:
    Code:
    Dim table As New DataTable
    
    With table.Columns
        .Add("File", GetType(String))
        .Add("Email", GetType(String))
    End With
    
    With table.Rows
        .Add("File A", "[email protected]")
        .Add("File B", "[email protected]")
        .Add("File C", "[email protected]")
        .Add("File B", "[email protected]")
        .Add("File C", "[email protected]")
        .Add("File A", "[email protected]")
    End With
    
    Dim emailByFile As New Specialized.NameValueCollection
    
    For Each row As DataRow In table.Rows
        emailByFile.Add(CStr(row("File")), CStr(row("Email")))
    Next
    
    For Each key As String In emailByFile.Keys
        MessageBox.Show(emailByFile(key), key)
    Next
    Last edited by jmcilhinney; Dec 4th, 2009 at 02:35 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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