Reading dataset into 2d array

callumh27

Member
Joined
Oct 6, 2009
Messages
7
Programming Experience
Beginner
Hi, I am new to databases and all the ADO what not. Anyway, I am having trouble reading the dataset into this 2 dimensional array. I know the dataset isn't blank, as I have been browsing it in other sub routines. I also know that the number of rows and columns have been correctly counted. However when I run this sub routine, It just displays a listbox of blank values. But if I uncomment the line where it assigns test to each value, it works fine.

VB.NET:
 See my reply -->

Any idea why the array values aren't filling with the dataset values?

Thankyou

Callum :)
 
Last edited:
VB.NET:
        Dim [COLOR="Red"]rows[/COLOR] As Integer = ds.Tables("Address Book").Rows.Count - 1
        Dim [COLOR="Blue"]cols[/COLOR] As Integer = ds.Tables("Address Book").Columns.Count - 1
        Dim table(rows, cols) As String
        For [COLOR="SeaGreen"]i[/COLOR] = 0 To rows
            For [COLOR="DarkOrange"]j[/COLOR] = 1 To cols ' 0 is primary key
                table([COLOR="Red"]rows[/COLOR], [COLOR="Blue"]cols[/COLOR]) = ds.Tables("Address Book").Rows([COLOR="Red"]rows[/COLOR]).Item([COLOR="Blue"]cols[/COLOR]).ToString
                'table(rows, cols) = "TEST"
            Next
        Next
Does that give you some idea? Which values are changing and which aren't in that code?
 
VB.NET:
        Dim rows As Integer = ds.Tables("Address Book").Rows.Count - 1
        Dim cols As Integer = ds.Tables("Address Book").Columns.Count - 1
        Dim table(rows, cols) As String

        For i = 0 To rows
            For j = 1 To cols ' 0 is primary key
                table(i, j) = ds.Tables("Address Book").Rows(i).Item(j).ToString
            Next
        Next

        'display contents

        For k = 0 To rows
            For l = 1 To cols
                ListBox1.Items.Add(table(k, l))
            Next
        Next

Fixed the mistake, for some reason I hadn't used the loop counters properly XD. This is what it was meant to be. Thanks anyway for your help, I just had a senior moment despite being a teenager XD
 
I'm rather curious as to why someone would do this, given that (for the most part) a DataTable is already effectively a 2D array of data.. I've seen people download database data into a DataTable and then ask how to transfer it into an array because arrays are what they understand; if this situation applies to you I'd advise you stick with the DataTable storage container and make the most of its featureset (which is considerably larger than an array)
 
Back
Top