Datasets join

Hi All,

I would truly appreciate help on the following matter:

I have two Datasets (each a result of a different database select):

1. Jobs: int jobid (primary key), string jobname, string jobtype.
2. UserJobs: userid, jobid (N-To-N relation).

I would like to create a dataset that will contain all the jobs of a certain user. For example, I want have a dataset with all the jobs of a user with userid=5.

How can I do that efficiently? (I have got about 100,000 records in the UserJobs table - for about 1000 users).



Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

U have to first have a DataRelation between the two tables in the dataset. Then create a DataViewManager which does the same function to a Dataset as a Dataview does to a DataTable.


      // Create DataView settings for each Table
      // using the DataViewManager
      DataViewManager myDVM = new DataViewManager(custDS);

      // Loop through the DataViewSettings and set Sort
      // or Rowfilter for each Table individually
      String myTable;
      foreach (DataViewSetting myDVS in myDVM.DataViewSettings)
        // Set Default Sort Order = Primary Key for all Tables
        myDVS.ApplyDefaultSort = true;

        // Set individual Sort and Rowfilter ...
        myTable = myDVS.Table.ToString();
         if (myTable == "UserJobs")
          myDVS.RowFilter = "userid = '5'

// Or u can do this directly like this
      myDVM.DataViewSettings["JobDetails"].RowFilter =
        "userid = 5";

       dataGrid.SetDataBinding(myDVM, "Jobs");

For more details on the samples . Follow this link

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.