Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. DataSet Relations

DataSet Relations

Scheduled Pinned Locked Moved C#
helptutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    totig
    wrote on last edited by
    #1

    Hi, I am not fully sure how to do the following, please help if you can. I have two tables (As far as I know I have not set a join between them). I need to view values from both tables (they have a common id, invProductID). The rule is, If a number I specify is in the first table, then show the values I want. However, I have not been able to get this to work. I am using a dataset and/or dataTables. I know I can do this by updating the dataAdapter, but the problem is I cant do that until a later stage. If you need any more information, please let me know. Thanks in advance.

    X X 2 Replies Last reply
    0
    • T totig

      Hi, I am not fully sure how to do the following, please help if you can. I have two tables (As far as I know I have not set a join between them). I need to view values from both tables (they have a common id, invProductID). The rule is, If a number I specify is in the first table, then show the values I want. However, I have not been able to get this to work. I am using a dataset and/or dataTables. I know I can do this by updating the dataAdapter, but the problem is I cant do that until a later stage. If you need any more information, please let me know. Thanks in advance.

      X Offline
      X Offline
      xoph
      wrote on last edited by
      #2

      I suggest you create a typed dataset with both your tables in it. When you create a typed dataset, the typed dataset class will automatically include a method to find rows by the primary key. (Make sure the primary key is defined in all your tables in your dataset!) For example, if your table is called "Product" and has "ProductID" as primary key, the typed dataset will provide a method called FindByProductID(int value). You can iterate throuh the rows collection of your second table, get the productid of the current row and then go to the first table and retrieve the related record by calling FindByProductID. That is 1 way of doing it without data relations. Of course you could also create a data relation in your dataset, and use getchilds or getparent methods in the dataset to navigate along foreign keys. :-OChris

      T 1 Reply Last reply
      0
      • X xoph

        I suggest you create a typed dataset with both your tables in it. When you create a typed dataset, the typed dataset class will automatically include a method to find rows by the primary key. (Make sure the primary key is defined in all your tables in your dataset!) For example, if your table is called "Product" and has "ProductID" as primary key, the typed dataset will provide a method called FindByProductID(int value). You can iterate throuh the rows collection of your second table, get the productid of the current row and then go to the first table and retrieve the related record by calling FindByProductID. That is 1 way of doing it without data relations. Of course you could also create a data relation in your dataset, and use getchilds or getparent methods in the dataset to navigate along foreign keys. :-OChris

        T Offline
        T Offline
        totig
        wrote on last edited by
        #3

        Hi, I have done what you suggested, but having a problem in one final area. I need to load the new dataSet with information from an existing dataSet, I am trying to do something like : prodInventoryDataSet1.products = generalDataSet.Tables["products"].Copy(); Of course, this does not work, I was wondering if there was a way to do it.

        X 1 Reply Last reply
        0
        • T totig

          Hi, I am not fully sure how to do the following, please help if you can. I have two tables (As far as I know I have not set a join between them). I need to view values from both tables (they have a common id, invProductID). The rule is, If a number I specify is in the first table, then show the values I want. However, I have not been able to get this to work. I am using a dataset and/or dataTables. I know I can do this by updating the dataAdapter, but the problem is I cant do that until a later stage. If you need any more information, please let me know. Thanks in advance.

          X Offline
          X Offline
          xfqiu
          wrote on last edited by
          #4

          DataColumn parentCol; DataColumn childCol; // Code to get the DataSet not shown here. parentCol = DataSet1.Tables["Customers"].Columns["CustID"]; childCol = DataSet1.Tables["Orders"].Columns["CustID"]; // Create DataRelation. DataRelation relCustOrder; relCustOrder = new DataRelation("CustomersOrders", parentCol, childCol); // Add the relation to the DataSet. DataSet1.Relations.Add(relCustOrder); Future belongs to C#!

          1 Reply Last reply
          0
          • T totig

            Hi, I have done what you suggested, but having a problem in one final area. I need to load the new dataSet with information from an existing dataSet, I am trying to do something like : prodInventoryDataSet1.products = generalDataSet.Tables["products"].Copy(); Of course, this does not work, I was wondering if there was a way to do it.

            X Offline
            X Offline
            xoph
            wrote on last edited by
            #5

            Try one of the Merge overloaded methods, something like targetDataSet.Merge(sourceDataSet) when you need the data from one dataset to be copied into one another. Chris

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups