Gani tpt
asked on
C# Or LINQ - how to merge two data sheets with different columns in c#
Hi,
I want to merge two data sheets with different columns in c#..
For example,
Based on my sheets and column mention, it should merge the data and display in final output as datatable.
Sheet1 ==> columnA data and columnC data
sheet3 ==> columnD data and Column F data
datatable result ==> merge of ColumnA & ColumnC as one column
merge of ColumnD & ColumnF as another column
my input string is sheet and column.
for example,
inPut string Sheets ==> "Sheet1" and "Sheet3"
Input string Columns ==> ColumnA & ColumnC(Sheet1)
ColumnD & ColumnF(Sheet3)...
How to form code in either LINQ or C#..?
I want to merge two data sheets with different columns in c#..
For example,
Based on my sheets and column mention, it should merge the data and display in final output as datatable.
Sheet1 ==> columnA data and columnC data
sheet3 ==> columnD data and Column F data
datatable result ==> merge of ColumnA & ColumnC as one column
merge of ColumnD & ColumnF as another column
my input string is sheet and column.
for example,
inPut string Sheets ==> "Sheet1" and "Sheet3"
Input string Columns ==> ColumnA & ColumnC(Sheet1)
ColumnD & ColumnF(Sheet3)...
How to form code in either LINQ or C#..?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just for completeness, you could also perform a Method Based Join:
-saige-
var people = names.Join(demographics,
name => name.ID,
demographic => demographic.ID,
(name, demographic) => new { name.ID, name.FirstName, name.LastName, demographic.Birthdate, demographic.IsWorking }).ConvertToDataTable();
Or an Expression Based Join:
var people = (from name in names
join demographic in demographics
on name.ID equals demographic.ID
select new { name.ID, name.FirstName, name.LastName, demographic.Birthdate, demographic.IsWorking }).ConvertToDataTable();
-saige-
ASKER