Array browser - Dataset population from array

I want to display to users the contents of a 2 dimensional array but have not found a way to populate a dataset with the values from the array.

It seems the only thing a dataset expects as source is a file. (Access etc).

I have even tried using ADODB.Recordset approach to no avail.

Has anyone any experience with VS 2005/Net 2.0 with browsing a virtual db in this manner.

Can someone point me to some examples of how to get this array data into the dataset so the datagridview columns can be populated. The max array size is 128 rows by 11 columns.

Thanks

Al

[611 byte] By [alp99] at [2008-1-9]
# 1

Does this help?

Code Snippet

Private Function TwoDArrayToDataTable(ByVal a As Array) As DataTable

Dim dt As New DataTable

For j As Integer = 0 To a.GetUpperBound(1)

dt.Columns.Add("Col " & j.ToString(System.Globalization.CultureInfo.InvariantCulture))

Next j

For i As Integer = 0 To a.GetUpperBound(0)

Dim dr As DataRow = dt.NewRow

For j As Integer = 0 To a.GetUpperBound(1)

dr(j) = a.GetValue(i, j)

Next j

dt.Rows.Add(dr)

Next i

Return dt

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim a As String(,) = New String(,) {{"A", "B", "C", "D"}, {"E", "F", "G", "H"}}

DataGridView1.DataSource = TwoDArrayToDataTable(a)

End Sub

Note that I pass the array as type Array instead of a specific type so that this will work in general for 2D arrays.
BinaryCoder at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Perfect, Thanks.

Sometimes just cannot see the forest for the trees.

alp99 at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...