SELECT data from DataSet tables

F

Frank Uray

Hi all

I have a DataSet with 2 tables.
Now I want to select data like a INNER JOIN from these tables.

In SQL Syntax I would write:
SELECT *
FROM table1 t1
INNER JOIN table2 t2
ON t1.f1 = t2.f1
WHERE t2.xy = 'search'

How do I select data like this from a DataSet ??
Or how else can I select data from a DataSet
when I want to get a combination of two or
more tables ??

Thanks for any comments

Best regards
Frank
 
M

Marc Gravell

Well, in .NET 3.5 you could probably use LINQ-to-objects to do this as a
join directly, but it looks like you should really be looking via the
DataRelations, where you have a DataRelation linking the two "f1"s. Then
you can use GetParentRow(relation) or GetChildRows(relation) to do the
navigation.

Does that help at all?

Marc
 
F

Frank Uray

Hi Marc

Thanks for your answer.

I will have to try with GetParentRow/GetChildRow
I did never try with this.

But I ab wondering how other people work with
complex data structures in Datasets ...

Best regards
Frank
 
M

Marc Gravell

I've wondered that myself ;-p

(I'm not a big user of datasets, so I can't answer it, I'm afraid)

Marc
 
F

Frank Uray

:)))

Me too, I used to build online apps with
DataReader's.
But now I have to build a application with
offline (xml file) modus ...

Thanks anyway
Frank
 
T

Tim Jarvis

Frank said:
Me too, I used to build online apps with
DataReader's.
But now I have to build a application with
offline (xml file) modus ...

Hi Frank,

If you have the option, push very hard to be able to use Linq for
DataSets (.NET 3.5) I guarantee that you will never want to navigate
datasets (or for that matter raw XML) any other way...

DataTable orders = ds.Tables["SalesOrderHeader"];
DataTable orderLines = ds.Tables["SalesOrderDetail"];

var ordersQuery = orders.AsEnumerable();
var orderLinesQuery = orderLines.AsEnumerable();

var query = from o in ordersQuery
join ol in orderLinesQuery
on o.Field<int>("SalesOrderID") equals
ol.Field<int>("SalesOrderID")
where o.Field<bool>("OnlineOrderFlag") == true &&
o.Field<DateTime>("OrderDate").Month == 8
select new { SalesOrderID = o.Field<int>("SalesOrderID"),
SalesOrderDetailID =
ol.Field<int>("SalesOrderDetailID"),
OrderDate = o.Field<DateTime>("OrderDate"),
ProductID = ol.Field<int>("ProductID") };


Cheers Tim.

--
 
G

Gary Winey

Hello Tim,

What references do you need to set in order to be able to run your code?
 
T

Tim Jarvis

Gary said:
Hello Tim,

What references do you need to set in order to be able to run your
code?

Hi Gary,

Sorry for the delay, I have been away and not read any newsgroups for a
while.

You need to be targetting framework 3.5, you will also need to
reference the System.Xml.Linq assembly and namespace.

Regards Tim.

--
 

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

Top