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

  • SEARCH
  • Home
  • 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 6044647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:02:07+00:00 2026-05-23T07:02:07+00:00

I have a DataTable which contains data in this format. I want to convert

  • 0

I have a DataTable which contains data in this format. I want to convert it to another format.
What is the simplest way to achieve this? maybe using lambda expression. I am using
C# 4.0

dattable1:
    seq     id        Amt
=============================
    1     00782       10 
    2     00782       20
    3     00782       30

    1     003850      40
    2     003850      50
    3     003850      60

    1     005723      70
    2     005723      80
    3     005723      90


To be stored in another datatable or list in this format

1  00782  003850  005723  10  40  70
2  00782  003850  005723  20  50  80
3  00782  003850  005723  30  60  90

example 2

 dattable1:
        seq     id        Amt
    =============================
        1     00782       10 


        1     003850      40


        1     005723      70



    To be stored in another datatable or list in this format

    1  00782  003850  005723  10  40  70
  • 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-23T07:02:08+00:00Added an answer on May 23, 2026 at 7:02 am

    This will generate the input that matches what you asked for.

    var datatable1 = new[]
    {
        new { seq = 1, id = "00782", Amt = 10 }, 
        new { seq = 2, id = "00782", Amt = 20 }, 
        new { seq = 3, id = "00782", Amt = 30 }, 
        new { seq = 1, id = "003850", Amt = 40 }, 
        new { seq = 2, id = "003850", Amt = 50 }, 
        new { seq = 3, id = "003850", Amt = 60 }, 
        new { seq = 1, id = "005723", Amt = 70 }, 
        new { seq = 2, id = "005723", Amt = 80 }, 
        new { seq = 3, id = "005723", Amt = 90 }
    };
    
    
    var result = datatable1
        .GroupBy(arg => arg.seq)
        .Select(arg =>
            new
            {
                arg.Key,
                id1 = "00782",
                id2 = "003850",
                id3 = "005723",
                Amt1 = arg.Where(x => x.id == "00782").Sum(x => x.Amt),
                Amt2 = arg.Where(x => x.id == "003850").Sum(x => x.Amt),
                Amt3 = arg.Where(x => x.id == "005723").Sum(x => x.Amt),
            })
        .ToList();
    

    [Edit]

    For “all scenarios”:

    var result = datatable1
        .GroupBy(arg => arg.seq)
        .Select(arg =>
            new
            {
                arg.Key,
                Ids = arg.Select(x => x.id).ToList(),
                Amounts = arg.Select(x => x.Amt).ToList(),
            })
        .ToList();
    
    foreach (var row in result)
        Console.WriteLine("{0}\t{1}\t{2}", row.Key, string.Join("\t", row.Ids), string.Join("\t", row.Amounts));
    

    Output:

    1       00782   003850  005723  10      40      70
    2       00782   003850  005723  20      50      80
    3       00782   003850  005723  30      60      90
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a datatable which contains InvalidCodes. Before uploading the data to database(data is
I have a huge data.table in R which contains the result of a experiment:
I have a DataTable which I want to save to a SQLite Database Table.
I have a DataTable which I select from database (Well, these data cross several
I have a System.Data.DataTable which is populated by reading a CSV file which sets
EDIT: I am using VS2008, .NET 3.5 I have a DataTable, which is populated
I have a ListView which is using a GridView to display a DataTable and
I have created a user control that contains a button. I am using this
I have a DataTable which I want to check if values in three of
I have a simple data table which contains dynamic form text fields. Each field

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.