column name doesnt matter, the data type might; This is essentially what you need to do:
Dim tbl as new datatable
Dim dt as new datatable
Dim dr, rwLoop as DataRow
Dim dc, dcloop as DataColumn
Dim i as integer
'Construct the table structure
'You have to do this for each column you want in the table
'I suggest leaving the datatype as string
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String") 'System.String is case sensitive
dc.ColumnName = "[Column Name]"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
For each tbl in dataset.tables
For each rwLoop in tbl.rows
dr = dt.NewRow
For each dcLoop in tbl.Columns
dr.Item(i) = rwLoop(i)
dt.Rows.Add(dr)
i += 1
Next
i = 0
next
Next
What this does is dynamically loop through all columns that you have created progmatically and all columns in X table. For this to work, the columns you create in your progmatic datatable must match the number of columns in each table in the data set.
When your done do this:
datagrid.datasource = dt
datagrid.databind()
"The one language all programmers understand is profanity."
|