DataTables and Inner Join

P

Prasun

Hello:

Is it possible to create a datatable that is an Inner Join of two existing
datatables in a Dataset. If so, how do you do so?

Thank You
Prasun
 
W

W.G. Ryan eMVP

Probably the best way to do this is to fill the original datatable with the
results of a Join statement. The short answer, as far as doing this
directly w/ two data tables is No. you can specify a datarelation - but if
values aren't present in the parent table, then a constraint will be
violated. AFAIK, the only way to get there other than pulling the joined
data into the table from the server is looping through everything and
building it yourself.
 
S

Sahil Malik [MVP]

I've answered this before -

http://groups-beta.google.com/group...oin+sahil+malik&rnum=1&hl=en#e052ed04ab6f4e09

But copy pasted here for your convenience (do read the above thread
though) -

"
Okay so if I understood your question correctly,


You have two tables. They have a common column. And you want to find all
rows, where that particular column value is the same in either table. Right?


Hmm ... Merge is not what you need then .. IMO.


You can however use DataTable.Select. The where clause you formualte for the
the Select method, will have to be formed over a loop from the first table.


So something like ..


Table2.Select("Ticker In (1,2,3,4)")


Where 1,2,3,4 are formed over a loop from Table1.Ticker.


BTW - I must add - DataTable.Select isn't the fastest pony in the stable, so
hopefully you don't have a lot of rows.


There are other ways to do this too - but the above is the most
straightforward. "

- Sahil Malik [MVP]
http://codebetter.com/blogs/sahil.malik/
 
P

Prasun

Hello:

I totally messed up when asking the question.... Here is my problem
statement/ background

Background: My program reads an excel file and populates three datatables
depending on the value in one of the columns. Now when i create a
datarelation and try to combine the tables, I loose values that are unique
in the child tables. I want to make sure that even those values will get
transfered. Is there a way to go about this? That is why i was wondering if
there is a way i could program an OuterJoin, leftjoin or so. I could make
the two datatables, fill up excel sheets with that info and then start using
those table to make the outer join but wanted to make sure if there was an
easier way

All help would be appreciated,

Thank You
Prasun
 
Q

queryadataset

Check out http://www.queryadataset.com. The author provides an assembly that lets you perform complex SQL (UNION, JOINS, GROUP BY, HAVING, ORDER BY) on the tables in a dataset. You can event upload your own dataset and issue your own queries. If you can get something working the way you want, contact the author ([email protected]), he's really helpful.

Ad.


**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top