Subject: Dataset and data Table Queations
Posted By: maddy137 Post Date: 8/29/2006 5:33:29 PM
Hi Friends,

I have a dataset with 9 tables in it. I want to combine these 9 tables into  1 table to bind a ddata grid. I can't do anything on sqlserver side. SP is not in my hands .

What is appropriate way to do it .

Thanks in advance.

Madhavi.

Reply By: dparsons Reply Date: 8/29/2006 6:22:04 PM
Before you can even do this, do all 9 tables have the same columns?  (And by same i mean the same number as well as hold the same data type)

"The one language all programmers understand is profanity."
Reply By: maddy137 Reply Date: 8/29/2006 6:40:03 PM
No they have different datatypes and different column names

Reply By: dparsons Reply Date: 8/29/2006 7:16:00 PM
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."
Reply By: xiaosan-33 Reply Date: 8/30/2006 2:33:16 AM
Why?

I will kill you!

Go to topic 49043

Return to index page 190
Return to index page 189
Return to index page 188
Return to index page 187
Return to index page 186
Return to index page 185
Return to index page 184
Return to index page 183
Return to index page 182
Return to index page 181