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 8933197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:28:56+00:00 2026-06-15T09:28:56+00:00

I have a trouble while making header from Datatable’s values. I have a text

  • 0

I have a trouble while making header from Datatable’s values. I have a text file, which I search for some strings. split them and put them in Datatable. After that I use some linq codes to make column “Name” as header of this table. For small text file it works great but when i got little bigger files, my compiler throws MemoryOutOfExeption. So I’m asking how can I fix my code?

My Code:

        DataTable evHeader00 = resAtt.Copy();

        var prds1 = evHeader00.AsEnumerable() // make Name Values as header
                        .GroupBy(c => c["Name"])
                        .Where(g => !(g.Key is DBNull))
                        .Select(g => (string)g.Key)
                        .ToList();

        prds1.ForEach(p => evHeader00.Columns.Add(p, typeof(string))); // Here i got MemoryOutOfExeption

        foreach (var row in evHeader00.AsEnumerable())
        {
            if (!(row["Name"] is DBNull))
            {
                row[(string)row["Name"]] = row["Products"];
            }
        }

DataTable 1:

 ID    Name    Products
 1      a        A
 2      b        B
 3      c        C
...    ...      ...

Result:

ID     a   b   c   ...
1      A
2          B
3              C
...   ... ... ...  ...    
  • 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-06-15T09:28:58+00:00Added an answer on June 15, 2026 at 9:28 am
    1. Why do you need to copy the whole DataTable here?

      DataTable evHeader00 = resAtt.Copy();
      
    2. Why do you create a new List<String> here with all your data?

      var prds1 = evHeader00.AsEnumerable() // make Name Values as header
                      .GroupBy(c => c["Name"])
                      .Where(g => !(g.Key is DBNull))
                      .Select(g => (string)g.Key)
                      .ToList();
      

    So this should be more scalable:

    IEnumerable<string> data = resAtt.AsEnumerable()
                                     .Where(r => !r.Field<string>("Name") == null)
                                     .GroupBy(r => r.Field<string>("Name"))
                                     .Select(g => g.Key);
    

    or (as @Rawling has commented) by using Enumerable.Distinct which should be even more “memory-friendly”:

    IEnumerable<string> data = resAtt.AsEnumerable()
                                     .Where(r => !r.Field<string>("Name") == null)
                                     .Select(r => r.Field<string>("Name"))
                                     .Distinct();
    

    Now you can use a foreach to enumerate the result.

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

Sidebar

Related Questions

I have some troubles while writing logs from log4net to the file. I seem
I have been having some real trouble with this for a while. I am
i have a little trouble while making my first play application. I got a
I have been having trouble while attempting to use the nextLine() method from java.util.Scanner.
Hello I have been having trouble with this for a while now. I have
I have trouble shooting at file download problem. In Chrome, the download works fine.
I have trouble where, for some reason, SVN would only merge the newly generated
I'm having some trouble with making list of objects based on a condition on
I have some troubles to find the right loop to check if some values
I am making Shadowing application . I have in trouble that play music by

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.