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:
<Company>
<CompanyName>Company1</CompanyName>
<Name>Carrington Mortgage Services, LLC</Name>
<MAddress1>1610 E. Saint Andrew Place</MAddress1>
<MAddress2>B150</MAddress2>
<MCity>Santa Ana</MCity>
<MState>CA</MState>
<MZip>92705</MZip>
</Company>
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. :(
The easiest method I believe to handle this would be to create your own class as you mentioned :
public class Company
{
public string CompanyName {get; set;}
public string Name {get; set;}
public string AddressLineOne {get; set;}
public string AddressLineTwo {get; set;}
public string City {get; set;}
public string State {get; set;}
public string ZipCode {get; set;}
}
then you can create your Dictionary, which might look like this :
Dictionary<string, CompanyClass> companyDictionary = new Dictionary<string,CompanyClass>();
you will then want to iterate through each row in your tables and add to the Dictionary :
foreach(DataTable dt in yourDataSet.Tables)
{
foreach(DataRow row in dt.Rows)
{
CompanyClass currentCompany = new CompanyClass(){
CompanyName = dt["CompanyName"],
Name = dt["Name"],
AddressLineOne = dt["AddressLineOne"],
AddressLineTwo = dt["AddressLineTwo"],
City = dt["City"],
State = dt["State"],
ZipCode = dt["ZipCode"]
};
companyDictionary.Add(dt["CompanyName"], currentCompany);
}
}
//Iterate through your second table here
(I didn't get to test any of this code - so there may be syntax errors etc. Hopefully it puts you in the right direction)
artvindustri...
Member
14 Points
52 Posts
Dictionary From DataSet?
Jan 17, 2013 09:57 PM|LINK
Hello all, Soooooooo frustrated.
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:
<Company>
<CompanyName>Company1</CompanyName>
<Name>Carrington Mortgage Services, LLC</Name>
<MAddress1>1610 E. Saint Andrew Place</MAddress1>
<MAddress2>B150</MAddress2>
<MCity>Santa Ana</MCity>
<MState>CA</MState>
<MZip>92705</MZip>
</Company>
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. :(
I'm dying here.
Rion William...
All-Star
27906 Points
4618 Posts
Re: Dictionary From DataSet?
Jan 18, 2013 12:34 AM|LINK
The easiest method I believe to handle this would be to create your own class as you mentioned :
public class Company { public string CompanyName {get; set;} public string Name {get; set;} public string AddressLineOne {get; set;} public string AddressLineTwo {get; set;} public string City {get; set;} public string State {get; set;} public string ZipCode {get; set;} }then you can create your Dictionary, which might look like this :
you will then want to iterate through each row in your tables and add to the Dictionary :
foreach(DataTable dt in yourDataSet.Tables) { foreach(DataRow row in dt.Rows) { CompanyClass currentCompany = new CompanyClass(){ CompanyName = dt["CompanyName"], Name = dt["Name"], AddressLineOne = dt["AddressLineOne"], AddressLineTwo = dt["AddressLineTwo"], City = dt["City"], State = dt["State"], ZipCode = dt["ZipCode"] }; companyDictionary.Add(dt["CompanyName"], currentCompany); } } //Iterate through your second table here(I didn't get to test any of this code - so there may be syntax errors etc. Hopefully it puts you in the right direction)
artvindustri...
Member
14 Points
52 Posts
Re: Dictionary From DataSet?
Jan 18, 2013 04:33 PM|LINK
Rion,
I always appreciate your willingness to jump in and help out. Thanks for the suggesstion. It does help me understand a direction.
Which right now is important to me since all these OO concepts aren't clear to me right now.
Rion William...
All-Star
27906 Points
4618 Posts
Re: Dictionary From DataSet?
Jan 18, 2013 04:36 PM|LINK
No problem! Always glad to help :)