Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
How to group by tables in datatable and sum them using ER
Sarath Kankipati
Jan 19 2018 2:04 AM
152
Reply
I am a newbie here and I have an issue: I have 5 tables in my database with the same columns and headers, so I want to group by all the tables and I want to sum them.
Suppose if there is a column Amount which is present in all 5 tables, then I want to group by the Amount and I want to sum all the 5 table values using Entity Framework.
This is my code which I'm using to do group by, but I'm unable to do the sum:
private
DataTable ProcessData(DataSet ds)
{
DataTable dt =
new
DataTable();
dt = ds.Tables[0].AsEnumerable()
.GroupBy(r =>
new
{ Col1 = r[
"Name"
], Col2 = r[
"Amt"
], Col3 = r[
"Net"
], Col4 = r[
"Data"
] })
.Select(g => g.OrderBy(r => r[
"max"
]).First())
.CopyToDataTable();
return
dt;
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
What is a Friend class and friend attribute
how to download the image in asp.net.Image stored in db?