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
  1. Home
  2. General Programming
  3. C#
  4. DataSet to Dictionary Join?

DataSet to Dictionary Join?

Scheduled Pinned Locked Moved C#
tutorialquestion
7 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.
  • R Offline
    R Offline
    RickSharp
    wrote on last edited by
    #1

    Hello all, I have 2 Datasets. I've already asked how to join 2 DataSets and didn't get any answers that helped me. So I feel the easiest way to associate them now is to create a dictionary(s) for DataSet2. The 2 different DataSets have only 1 field in common, CompanyName. So enter dicitonary. DataSet 2 contains only 16 total records (Company). Each record (Company) has 7 rows: Company1 Carrington Mortgage Services, LLC 1610 E. Saint Andrew Place B150 Santa Ana CA 92705 So when CompanyName matches, return value from Dictionary. Do i need to create 16 Dicitonary entires with Key and Value? Do i create 1 Dictionary with variables populating on some kind of for loop? I was told that i could create my own class to store the information I need or simply set the dataset record as the value. No idea what any of those things mean. :(

    P 1 Reply Last reply
    0
    • R RickSharp

      Hello all, I have 2 Datasets. I've already asked how to join 2 DataSets and didn't get any answers that helped me. So I feel the easiest way to associate them now is to create a dictionary(s) for DataSet2. The 2 different DataSets have only 1 field in common, CompanyName. So enter dicitonary. DataSet 2 contains only 16 total records (Company). Each record (Company) has 7 rows: Company1 Carrington Mortgage Services, LLC 1610 E. Saint Andrew Place B150 Santa Ana CA 92705 So when CompanyName matches, return value from Dictionary. Do i need to create 16 Dicitonary entires with Key and Value? Do i create 1 Dictionary with variables populating on some kind of for loop? I was told that i could create my own class to store the information I need or simply set the dataset record as the value. No idea what any of those things mean. :(

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      If you do that (and I'm not saying you should or shouldn't) you probably ought to at least define a class to hold each entry and then have Dictionary<string,MyClass>

      R 1 Reply Last reply
      0
      • P PIEBALDconsult

        If you do that (and I'm not saying you should or shouldn't) you probably ought to at least define a class to hold each entry and then have Dictionary<string,MyClass>

        R Offline
        R Offline
        RickSharp
        wrote on last edited by
        #3

        Do you mean like this? public class Companies { public static String Company1 { get { return "Company1";}} public static String Company1City { get { return "Company1City";}} public static String Company1State { get { return "Company1State";}} public static String Company2 { get { return "Company2";}} public static String Company2City { get { return "Company2City";}} public static String Company2State { get { return "Company2State";}} } or like this? Public Class Company1 { } Public Class Company2 { }

        P H 2 Replies Last reply
        0
        • R RickSharp

          Do you mean like this? public class Companies { public static String Company1 { get { return "Company1";}} public static String Company1City { get { return "Company1City";}} public static String Company1State { get { return "Company1State";}} public static String Company2 { get { return "Company2";}} public static String Company2City { get { return "Company2City";}} public static String Company2State { get { return "Company2State";}} } or like this? Public Class Company1 { } Public Class Company2 { }

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Maybe more like the latter, but do you really need two classes? If so, possibly add a third (abstract) one, and an Interface! Oooh! And an equality operator! And and and...

          R 1 Reply Last reply
          0
          • P PIEBALDconsult

            Maybe more like the latter, but do you really need two classes? If so, possibly add a third (abstract) one, and an Interface! Oooh! And an equality operator! And and and...

            R Offline
            R Offline
            RickSharp
            wrote on last edited by
            #5

            No idea how to achieve all of that. Sorry. Beginner here. But your enthusiasm is, nice.

            1 Reply Last reply
            0
            • R RickSharp

              Do you mean like this? public class Companies { public static String Company1 { get { return "Company1";}} public static String Company1City { get { return "Company1City";}} public static String Company1State { get { return "Company1State";}} public static String Company2 { get { return "Company2";}} public static String Company2City { get { return "Company2City";}} public static String Company2State { get { return "Company2State";}} } or like this? Public Class Company1 { } Public Class Company2 { }

              H Offline
              H Offline
              HuorSwords
              wrote on last edited by
              #6

              class Company
              {
              public string Name { get; set; }

              public List Loans { get; }
              
              // The other properties / columns goes here...
              
              // Constructor
              public Company()
              {
              	this.Loans = new List();
              }
              

              }

              class Loan
              {
              public string CompanyName { get; set; }

              // The other properties / columns goes here...
              

              }

              static class Main()
              {
              Dictionary companies = new Dictionary();

              foreach (DataRow row in companyDataSet.Tables\["Company"\].Rows)
                  {		
              	Company current = new Company();
              	
              	current.Name = row.CompanyName;
              	// Fill here the other properties...
              }
              
              foreach (DataRow row in loanDataSet.Tables\["Loan"\].Rows)
                  {
              	Loan currentLoan = new Loan();
              	currentLoan.CompanyName = row.CompanyName;
              	// Fill here the other properties...
              	
              	companies\[currentLoan.CompanyName\].Loans.Add(currentLoan);
              }
              
              // FillGridViewWithDictionary(companies)...
              

              }

              R 1 Reply Last reply
              0
              • H HuorSwords

                class Company
                {
                public string Name { get; set; }

                public List Loans { get; }
                
                // The other properties / columns goes here...
                
                // Constructor
                public Company()
                {
                	this.Loans = new List();
                }
                

                }

                class Loan
                {
                public string CompanyName { get; set; }

                // The other properties / columns goes here...
                

                }

                static class Main()
                {
                Dictionary companies = new Dictionary();

                foreach (DataRow row in companyDataSet.Tables\["Company"\].Rows)
                    {		
                	Company current = new Company();
                	
                	current.Name = row.CompanyName;
                	// Fill here the other properties...
                }
                
                foreach (DataRow row in loanDataSet.Tables\["Loan"\].Rows)
                    {
                	Loan currentLoan = new Loan();
                	currentLoan.CompanyName = row.CompanyName;
                	// Fill here the other properties...
                	
                	companies\[currentLoan.CompanyName\].Loans.Add(currentLoan);
                }
                
                // FillGridViewWithDictionary(companies)...
                

                }

                R Offline
                R Offline
                RickSharp
                wrote on last edited by
                #7

                Huor, Thank so much for your time. This is very helpful and at least sends me in the right direction! It seems like most experienced programmers are too jaded to offer help here. Like giving a handout to a poor person that hasn't helped themselves. Like I'm just looking for a handout because I'm too stupid to google or use the "search" features. "Oh please Mr programming constultant, help me for free, please, my family is dying from starvation and and...my dog has fleas...I need more code" "Begone peasant!! I have no time for new coders! I'm solving much higher and more important recursion problems and pointer issues! Why don't you use the search feature." Bah!

                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