|
-
Dec 4th, 2009, 02:12 AM
#1
Thread Starter
Member
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.
-
Dec 4th, 2009, 02:30 AM
#2
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|