Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 677311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:01:32+00:00 2026-05-14T01:01:32+00:00

I have a untyped DataTable that looks like this (srcTbl): date col_1 col_2 …

  • 0

I have a untyped DataTable that looks like this (srcTbl):

date            col_1   col_2 ...  col_n
1.3.2010 00:00  12.5    0     ...  100 
1.3.2010 01:00  0       0     ...  100 
1.3.2010 22:00  0       0     ...  100 
1.3.2010 23:00  12.5    0     ...  100 
...
31.3.2010 00:00 2       0     ...  100
31.3.2010 01:00 2       0     ...  200

I need to sum up the rows grouped by dates to get a DataTable like that (dstTbl):

date,           col_1   col_2 ...  col_n
1.3.2010        15      0     ...  400
...
31.3.2010       4       0     ...  300

Is this possible by using LINQ and if then how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:01:32+00:00Added an answer on May 14, 2026 at 1:01 am

    Okay, So you can achieve it like this. This is a working version so you shouldn’t have much problem.

     

    DataTable myDataTable = new DataTable();
    myDataTable.Columns.Add("Date", typeof(DateTime));
    myDataTable.Columns.Add("Col1", typeof(int));
    myDataTable.Columns.Add("Col2", typeof(int));
    myDataTable.Columns.Add("Col3", typeof(int));

            var datarow1 = myDataTable.NewRow();
            datarow1.SetField("Date", DateTime.Parse("01/03/09 00:01:00"));
            datarow1.SetField("Col1", 12);
            datarow1.SetField("Col2", 0);
            datarow1.SetField("Col3", 100);
    
            var datarow2 = myDataTable.NewRow();
            datarow2.SetField("Date", DateTime.Parse("01/03/09 01:03:00"));
            datarow2.SetField("Col1", 12);
            datarow2.SetField("Col2", 0);
            datarow2.SetField("Col3", 100);
    
            var datarow3 = myDataTable.NewRow();
            datarow3.SetField("Date", DateTime.Parse("01/03/09 02:05:00"));
            datarow3.SetField("Col1", 0);
            datarow3.SetField("Col2", 0);
            datarow3.SetField("Col3", 100);
    
            var datarow4 = myDataTable.NewRow();
            datarow4.SetField("Date", DateTime.Parse("10/10/09 00:03:00"));
            datarow4.SetField("Col1", 2);
            datarow4.SetField("Col2", 0);
            datarow4.SetField("Col3", 100);
    
            var datarow5 = myDataTable.NewRow();
            datarow5.SetField("Date", DateTime.Parse("31/03/09 01:03:00"));
            datarow5.SetField("Col1", 2);
            datarow5.SetField("Col2", 0);
            datarow5.SetField("Col3", 100);
    
            var datarow6 = myDataTable.NewRow();
            datarow6.SetField("Date", DateTime.Parse("31/03/09 03:04:00"));
            datarow6.SetField("Col1", 2);
            datarow6.SetField("Col2", 0);
            datarow6.SetField("Col3", 100);
    
            myDataTable.Rows.Add(datarow1);
            myDataTable.Rows.Add(datarow2);
            myDataTable.Rows.Add(datarow3);
            myDataTable.Rows.Add(datarow4);
            myDataTable.Rows.Add(datarow5);
            myDataTable.Rows.Add(datarow6);
    
            var q = (from t in myDataTable.AsEnumerable()
                     group t by new {t.Field<DateTime>("Date").Day, t.Field<DateTime>("Date").Month, t.Field<DateTime>("Date").Year}
                     into temp
                        select myDataTable.LoadDataRow(
                        new object[]
                            {
                                string.Format("{0}.{1}.{2}", temp.Key.Day, temp.Key.Month, temp.Key.Year),
                                temp.Sum(r => r.Field<int>("Col1")),
                                temp.Sum(r => r.Field<int>("Col2")),
                                temp.Sum(r => r.Field<int>("Col3")),
                            }, LoadOption.PreserveChanges));
    
            DataTable newTable = q.CopyToDataTable();
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an existing application that relies heavily on stored procedures and untyped DataSets.
I have a record that looks similar to: type TNote = record Title :
I have to call some Java library code that returns an untyped java.util.List and
I have some (untyped) XML being stored in SQL Server 2005 that I need
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have an old untyped class pre Java1.5 and need to refactor it using
Some people have argued that the C# 4.0 feature introduced with the dynamic keyword
Have created simple Ajax enabled contact forms before that have around 12 fields -
Have a LinqtoSql query that I now want to precompile. var unorderedc = from
I have a strongly typed Person view, that I want to render a partial

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.