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:
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. :(

Akkiraju IvaturiPosted Jan 18, 2013, 9:47 AM
I am adding two data tables here. In your case get datatable from datasets as below.
DataTable dt1 = ds1.Tables[0];
DataTable dt2 = ds2.Tables[0];
//My Example
DataTable dt1=new DataTable("table1");
dt1.Columns.Add("CompanyName", typeof(string));
dt1.Columns.Add("Address", typeof(string));
DataTable dt2 = new DataTable("table2");
dt2.Columns.Add("CompanyName" typeof(string));
dt2.Columns.Add("CompanyID", typeof(string));
//Adding sample data
dt1.Rows.Add("Company1","Address1");
dt1.Rows.Add("Company2","Address2");
dt2.Rows.Add("Company1","ID1");
dt2.Rows.Add("Company3","ID3");
Now we want to get rows with criteria that company name matches in two tables. Use LINQ query and get the results:
var result = from table1 in dt1.AsEnumerable()
join table2 in dt2.AsEnumerable()
on (string) table1["CompanyName"] equals (string) table2["CompanyName"]
select new
{
Name = (string)table1["CompanyName"],
Address=(string)table1["Address"],
CompanyID=(string)table2["CompanyID"]
};
Now get the data (Matching rows):
foreach(var obj in result)
{
string CompanyName = obj.Name;
string Address = obj.Address;
string ID = obj.CompanyID;
}
Here we see matching company name is Company1 and so you should get only one resultset.
Akkiraju IvaturiPosted Jan 22, 2013, 2:14 PM
Rick SharpPosted Jan 22, 2013, 12:35 PM
Thank you so much. This is the answer I've needed for quite some time.
Apart of my problem was that I wasn't specifying the table in quotes while
declaring the DataTable so the query would not see the table.
DataTable dt = new Datatable("Company");
Akkiraju IvaturiPosted Jan 19, 2013, 12:29 AM
Rick SharpPosted Jan 18, 2013, 3:07 PM