Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

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, you're going to have to cheat a little. If you really want a DataView, I'd 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, you'll 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. It's similar to the first option on you don't 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 can't 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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

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.

Rufus

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...