SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : Microsoft .NET :

Previous DiscussionNext Discussion
 C# DataSet to DataTable

Ok, here is the issue. I have a DataSet (DS) that contains two tables (let's call them T1 and T2 for simplicity).

Well, I have created a relation in DS between T1 and T2, like this:

DS.Relations.Add("RELATION", DT1.Columns["MY_COLUMN"], DT2.Columns["MY_COLUMN"], false);

Now, what I want to do is to create a DataTable (ResultDT) based on the new DataSet (DS) that I created.

I'm in the process of converting a web project from VB.NET to C#, and I want to streamline the code.

In the VB.NET code, the Result DataTable is done by passing the DataSet (DS) into a Function, building the structure of the table, then using a For loop to iterate through the data in DS (adding the rows to ResultDT). Within that For loop, there is a For Each loop that iterates through T2 (using DS.Tables(0).Rows(X).GetChildRows("RELATION").

So, bottom line, I want to streamline this.

Is there any way to do this? In a nutshell, I want to take the data contained in DS (which is two DataTables), and combine that data into one DataTable (ResultDT). As simply and painlessly as possible.

Started By Monte on Nov 17, 2008 at 11:32:06 AM

18 Response(s) | Reply

Earlier Replies | Replies 12 to 18 of 18 | Later Replies
Goto Page: 3 2 1
bod1467 on Jan 7, 2009 at 6:47:46 AM (# 12)

Do a search on SQL JOIN ... there are ways of structuring the SQL command to get exactly what you want. :o)


brian on Jan 7, 2009 at 7:35:02 AM (# 13)

a join wouldn't affect the results if the above query pulls back the wrong results.

This wouldn't be a mysql database by any chance? I had fun with it a few years back

You could try using a

select a.*,b.* from a inner join b on a.field=b.field

but it is essentially the same as what you had before.


Monte on Jan 7, 2009 at 1:08:13 PM (# 14)

No, it's an Oracle database.

I have to use two queries, because one of them is dynamically generated based on certain code variables.


ChrisRickard on Jan 7, 2009 at 8:24:39 PM (# 15)

Hi Markus! Yeah I still lurk every once and a while, but even that's getting less and less.


brian on Jan 8, 2009 at 1:00:15 AM (# 16)

Chirs - you should use a feed reader. That wat you can stick your head in whenever you see something interesting.

Monte - why don't you just include the second part of the query in the dynamically generated one and eliminate the need for 2 queries?

you could do it something like

select a.*,b.*
from a,(select * from c) as b
where a.field=b.field

where the select * from c is your dynamic query. My oracle is a little rusty but I;m sure you could do that in a stored procedure or something.


Monte on Jan 8, 2009 at 4:08:48 AM (# 17)

It's the nature of the database. It's difficult to explain without going into a whole lot of detail.


AnnieCalvert on Jul 31, 2012 at 9:26:38 PM (# 18)

You need a service that can create an object based on varying input ( So, the object returned will always be the same, and only the input will differ? This does sound a lot like you have things a little confused in your code, and with some reorganization, you will just need to use the strategy pattern'
http://www.dapfor.com/en/net-suite/net-grid/tutorial/data-grouping


Earlier Replies | Replies 12 to 18 of 18 | Later Replies
Goto Page: 3 2 1

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2004 InsideDHTML.com, LLC. All rights reserved.