Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 29th, 2006, 05:33 PM
Authorized User
 
Join Date: Apr 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dataset and data Table Queations

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.

 
Old August 29th, 2006, 06:22 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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."
 
Old August 29th, 2006, 06:40 PM
Authorized User
 
Join Date: Apr 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No they have different datatypes and different column names

 
Old August 29th, 2006, 07:16 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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."
 
Old August 30th, 2006, 02:33 AM
Registered User
 
Join Date: Aug 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to xiaosan-33 Send a message via MSN to xiaosan-33
Default

Why?

I will kill you!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Table data is Right, DataSet is Wrong Charlie05 VB Databases Basics 1 August 21st, 2007 09:04 PM
removing table from dataset msrnivas .NET Web Services 0 October 25th, 2004 05:26 AM
Creating a new table from a dataset... vb_developer SQL Server ASP 4 September 21st, 2004 07:41 AM
dataset column not in data base table gbuller ADO.NET 4 August 18th, 2004 10:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.