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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:48:21+00:00 2026-05-25T01:48:21+00:00

My Datatable has some columns that contains data in the format as 2011~|~2012~|~2013. Now

  • 0

My Datatable has some columns that contains data in the format as 2011~|~2012~|~2013. Now the table has only one row. But based on how many such data is there, that many rows should be created

Hence, in the above format, three rows should be created each having Year column filled as 2011, 2012 and 2013. It doesn’t matter that if other columns are being duplicated

Format similar to Year column also exists for some 2-3 more columns such as Sales column states figures as 190~|~250~|~488.

One Important Note: The number of rows here should be 3 (considering year & sales column). It should not be 9 (3 x 3). There is a one-to-one relationship, say in year 2011 sales was 190mn$, for 2012 it was 250 mn$ and for 2013 expected is 488mn$.

The below image explains more in detail.

I guess the funda is cleared. If not, let me know.

Please guide

Image Added

  • 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-25T01:48:21+00:00Added an answer on May 25, 2026 at 1:48 am

    Are you looking for something like this?

    private DataTable AlterDataTable(DataTable oldTable)
    {
        DataTable newTable = oldTable.Clone();
        foreach (DataRow row in oldTable.Rows)
        {
            var years = row["Year"]
            .ToString()
            .Split(new string[] { "~|~" }, StringSplitOptions.RemoveEmptyEntries)
            .ToList();
            foreach (var year in years)
            {
                row["Year"] = year;
                newTable.ImportRow(row);
            }
    
        }
    
        return newTable;
    }
    

    Call it as DataTable dataTable = AlterDataTable(dt);

    For this requirement, try this

    private DataTable AlterDataTable(DataTable oldTable)
    {
        DataTable newTable = oldTable.Clone();
        foreach (DataRow row in oldTable.Rows)
        {
            var years = row["Year"]
            .ToString()
            .Split(new string[] { "~|~" }, StringSplitOptions.RemoveEmptyEntries)
            .ToList();
            var sales = row["Sales"]
            .ToString()
            .Split(new string[] { "~|~" }, StringSplitOptions.RemoveEmptyEntries)
            .ToList();
            if (years.Count != sales.Count)
            {
                throw new Exception("Argument count mismatch exception");
            }
            for (var i = 0; i < years.Count; i++)
            {
                row["Year"] = years[i];
                row["Sales"] = sales[i];
                newTable.ImportRow(row);
            }
        }
        return newTable;
    }
    

    Please note that the splits should be having the same count.

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

Sidebar

Related Questions

I have a data table that has the following columns: id (string), date (date),
I have a data table which already has some values, plus it is getting
I have produced a data table. All the columns are sortable. It has a
I have a web user control, that has a table with 3 columns 1)
I have a DataTable which has 10 columns, and after I add some rows
I have a DataTable, which has a number of columns. Some of those columns
I have some C# code that looks something like this System.Data.DataRow row; var table
I have a table that has a column that contains links. Each cell in
I have a DataGridView in a form that has a data table as the
I have a DataTable that has a boolean column called [Invalid]. I need to

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.