DataRelation question (C#)

niv

Member
Joined
Jun 3, 2003
Messages
9
DataRelation question

Hello,

I have 3 tables

Tables
Chairs
TableToChair_Relationship


I am working with these tables seperately. I have found
that by using a dataview, I can filter the datatable.
This is great... what I need to do now is to
relate Tables to TableToChair_Relationship to Chairs using
a datarelation.

Questions:
(1)Can I relate 3 tables using the datarelation?
(2)How do I use dvNew.RowFilter to only return all chairs
that can be available for a given table.
(3)I currenly set the dataview to a datatable.
dvNew.Table = dsTest.Tables[0];

Should I set the dataview.Table to the datarelation?

Thank You,

niv
 
The only reason you would need a 3rd table is to support a many-to-many relationship. First, is that what you need? If so, proceed. If not, skip this and redesign your data structure :)

For a many to many in a DataSet, youre going to have to cheat a little. If you really want a DataView, Id suggest adding a column to one of the tables. It should be an expression column with the Foreign Key from the 3rd table. You can use the Child or Parent "function" in the expression (look at the help) to essentially pull out a value from a table and have it appear as a column in the parent or child table.

Once you have that column, you can simple filter as normal.

If the point is merely to filter Chairs by a particular table or vice versa and fill a combo or listbox, you can always loop and add items manually to a control. If you need binding, youll have to use the first method.

There is a 3rd alternative (maybe more - this is all I can think of right now) - use a new class called JoinView that essentially works like a View from SQL Server. Its similar to the first option on you dont add a new column to the DataSet, you define a JoinView (like a DataView) to have the other column. The only problem is the JoinView class is only provided as-is via source from Microsoft, and only in VB.NET. I ported it to C# but I cant share it (I had to bill a client for the time spent). I can say it took about 3 or 4 hours doing it by hand but it works fantastically well.

Good luck!

-nerseus
 
you relate 3 tables by 1-1-1 forum.

you can filter the rows by using the select method, in datatables.
select takes 3 arguments sort,filter,rowstate, you can specify the filter as an condition or anything you want to filter, by giving commands.


hope this would help.
 
Back
Top