Databinding with intermediary table

Z

Zebrahead

Hi all,

I have a dataset with 3 tables:
1. Items with columns: ItemId, Name
2. Categories with columns: CategoryId, name
3. ItemsCategory with columns: ItemId, CategoryId (serves to identify which
items belong to which categories.)

When the user selects a category from a dropdown list I need to display the
Items for that category in another dropdown list. Before I used to go to the
database every time and get the data with a query like:

SELECT Items.ItemId, Items.Name FROM Items, ItemsCategory WHERE
ItemsCategory.CategoryId = list.SelectedIndex and Items.ItemId =
ItemsCategory.ItemId.

How do I perform a similar query with a dataset?

So far I have been able to get the Items for the selected Category by using:

DataView cView = new DataView(ItemsSet.Tables["ItemsCategory"],
"","CategoryId", DataViewRowState.CurrentRows);
DataRowView[] foundRows = cView .FindRows(new object[]
{list.SelectedIndex.ToString()});

But I am unable to make my Items dropdown list display only those Items.
(The Items.ItemId column is the Items' dropdown list's datavaluefield)
Creating a datarelation between the Items and ItemsCategory table has no
effect and creating a datarelation berween Items and DataRowView generates an
error.

Any suggestions and/or links to tutorials greatly appreciated!

Thanks in advance!

Zebrahead.
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top