Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataTables question

Status
Not open for further replies.

jby1

Programmer
Apr 29, 2003
403
GB
Hi

I have typed DataSet containing a number of related DataTables.

For example, suppose I have Table1 and Table2

Table1 has columns ColA, ColB, ColC

and Table2 has columns ColZ, ColA

Table1 primary key is ColA
Table2 primary key is ColZ/ColA

I want to get all rows from Table1, where Table2 has a given value of ColZ (eg 1)

If this was SQL, I would do something like

Code:
select a.ColA, a.ColB, a.ColC
from Table1 a
inner join Table2 b on a.ColA = b.ColA
where b.ColZ = 1

Can anybody tell me how I can do this in my DataSet?

It has been driving me mad trying to figure it out!
 
One way is to use the DataView object.
My C# code is off the top of my head. Syntax may not be 100% right.

int colValue;
DataView dv2 = new DataView(Table2);
DataView dv1 = new DataView(Table1);

dv2.RowFilter = "ColZ = 1";
colValue = dv2(0)("ColA").ToInt32(); //syntax?

dv1.RowFilter = "ColA = colValue";

I hope this helps

 
Thanks for you answer.

I eventually worked out a solution using DataRelations and the GetParentRows/GetChildRows methods.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top