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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:48:15+00:00 2026-06-11T21:48:15+00:00

My Table1 has some Header and Values: KundeID KundeName Produkt Comment 1 Michael Jogurt

  • 0

My Table1 has some Header and Values:

KundeID KundeName  Produkt   Comment

1       Michael    Jogurt   "nichts"  
2       Raj                 "Ich bin cool"     
3       Gary       Fanta    "yahoo"  
4       Miky       Sprite  

I want to change to Table2, make Values from Produkt as Header Columns:

KundeID KundeName Comment        Jogurt Fanta Sprite    

1       Michael   "nichts"         x
2       Raj       "Ich bin cool"           
3       Gary      "yahoo"                 x     
4       Miky                                     x         

My code for Table1:

DataTable table = new DataTable("Kunde");

        table.Columns.Add("KundeID", typeof(Int32));
        table.Columns.Add("KundeName", typeof(String));
        table.Columns.Add("Produkt", typeof(String));

        DataTable comment = new DataTable("Comment"); 

        comment.Columns.Add("KundeName", typeof(String));
        comment.Columns.Add("Comment", typeof(String));

        DataSet ds = new DataSet("DataSet");

        ds.Tables.Add(table);
        ds.Tables.Add(comment);

        object[] o1 = { 1, "Michael", "Jogurt" };
        object[] o2 = { 2, "Raj" };
        object[] o3 = { 3, "Gary", "Fanta" };
        object[] o4 = { 4, "Miky", "Sprite" };

        object[] c1 = { "Raj", "Ich bin cool" };
        object[] c2 = { "Gary", "yahoo" };
        object[] c3 = { "Michael", "nichts" };

        table.Rows.Add(o1);
        table.Rows.Add(o2);
        table.Rows.Add(o3);
        table.Rows.Add(o4);

        comment.Rows.Add(c1);
        comment.Rows.Add(c2);
        comment.Rows.Add(c3);

        var results = from table1 in table.AsEnumerable()
                      join table2 in comment.AsEnumerable()
                      on table1.Field<string>("KundeName") equals table2.Field<string>("KundeName") into prodGroup
                      from table4 in prodGroup.DefaultIfEmpty()

                      select new
                          {
                              KundeID = table1.Field<Int32?>("KundeID"),
                              KundeName = table1.Field<String>("KundeName"),
                              Produkt = table1.Field<String>("Produkt"),
                              Comment = table4 != null ? table4.Field<String>("Comment") : null,
                          };
dataGridView1.DataSource = results.ToList();

How can I take Value from “Produkt” and make it Header? thank you guys for helping

  • 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-11T21:48:16+00:00Added an answer on June 11, 2026 at 9:48 pm

    This should do the trick regardless of how many different products come up. It’s pretty short and concise.

    // build the new data table
    var result = new DataTable();
    result.Columns.Add("KundeID", typeof(Int32));
    result.Columns.Add("KundeName", typeof(String));
    result.Columns.Add("Comment", typeof(String));
    result.Columns.AddRange(
        (from c in 
             (from r in table.AsEnumerable() 
              where !r.IsNull("Produkt") && !string.IsNullOrEmpty(r.Field<string>("Produkt")) 
              select r.Field<string>("Produkt")).Distinct()    // added DISTINCT
         select new DataColumn(c, typeof(bool))).ToArray()
    );
    
    foreach (var r in results)
    {
        var productIndex = result.Columns.IndexOf(r.Produkt);
        var vals = new List<object>() { r.KundeID, r.KundeName, r.Comment };
        for (int i = 3; i < result.Columns.Count; i++)
        {
            if (i == productIndex)
            {
                vals.Add(true);
            }
            else
            {
                vals.Add(false);
            }
        }
    
        result.LoadDataRow(vals.ToArray(), true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some older (broken) code that has a join using a *= table1.ID
I have a data table which already has some values, plus it is getting
I have a table with a header and some rows. Each row has its
I've got a table that has some <input type=text> boxes in it, and I
I have an access table which has some cells as blank ( no data
I've got a form inside a table that has some Javascript validation. The table
My app has some table cells that vary in height. The cells can also
my table has the following fields videos |id| |average| |views| now i select some
Hi I had parent table which has ID and some other columns and a
I have two tables. One has some product details, the other holds various photos

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.