Hi,
I have been searching for quite a while about joining multiple datatables via LINQ to dataset (When i say multiple, i don't mean just 2!!!), and it seems there aren't lot of examples in the net. I have seen examples of joining two datatables, done that, no problem there. Now i want to join three datatables. And there's nothing i can find out there.
For example i have a 3 datatables:
PERSON (columns: person_id, name, gender_code, ethnic_code)
GENDER (columns: gender_code, gender_descript ion)
ETHNICITY (cols: ethnic_code, ethnic_descript ion)
with sample records of:
PERSON:
p001, John B. Jones, m, 1
p002, Misa L. Campo, f, 3
GENDER:
m, Male
f, Female
ETHNICITY:
1, White American
2, African American
3, Asian
I'm hoping to display something like this:
p001, John B. Jones, Male, White American
p002, Misa L. Campo, Female, Asian
I have the ff codes:
I believe i'm doing this right up to this point, now the problem is i cant use the CopyToDataTable method on joinedResult. Any help would be greatly appreciated.
Thanks guys,
I have been searching for quite a while about joining multiple datatables via LINQ to dataset (When i say multiple, i don't mean just 2!!!), and it seems there aren't lot of examples in the net. I have seen examples of joining two datatables, done that, no problem there. Now i want to join three datatables. And there's nothing i can find out there.
For example i have a 3 datatables:
PERSON (columns: person_id, name, gender_code, ethnic_code)
GENDER (columns: gender_code, gender_descript ion)
ETHNICITY (cols: ethnic_code, ethnic_descript ion)
with sample records of:
PERSON:
p001, John B. Jones, m, 1
p002, Misa L. Campo, f, 3
GENDER:
m, Male
f, Female
ETHNICITY:
1, White American
2, African American
3, Asian
I'm hoping to display something like this:
p001, John B. Jones, Male, White American
p002, Misa L. Campo, Female, Asian
I have the ff codes:
Code:
Dim joinedResult = _
From p In PERSON.AsEnumerable() _
Join g In GENDER.AsEnumerable() _
On g.Field(Of string)("gender_code") Equals p.Field(Of string)("gender_code") _
Join e In ETHNICITY.AsEnumerable() _
On e.Field(Of STRING)("ethnic_code") Equals p.Field(Of string)("ethnic_code") _
Select _
id = p.Field(Of String)("person_id"), _
name = p.Field(Of String)("name"), _
gender = g.Field(Of String)("gender_description"), _
ethnicity = e.Field(Of String)("ethnic_description")
Thanks guys,
Comment