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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:53:46+00:00 2026-06-06T10:53:46+00:00

I am importing data from csv file, sometimes there are column headers and some

  • 0

I am importing data from csv file, sometimes there are column headers and some times not the customer chooses custom columns(from multiple drop downs)

my problem is I am able to change the columns type and name but when I want to import data row into cloned table it just adds rows but no data with in those rows. If I rename the column to old values it works, let’s say column 0 name is 0 if I change that to something else which I need to it won’t fill the row below with data but If I change zero to zero again it will any idea:

here is my coding:

 #region Manipulate headers

            DataTable tblCloned = new DataTable();
            tblCloned = tblDataTable.Clone();
            int i = 0;

            foreach (string item in lstRecord)
            {

                if (item != "Date")
                {
                    var m = tblDataTable.Columns[i].DataType;
                    tblCloned.Columns[i].DataType = typeof(System.String);
                    tblCloned.Columns[i].ColumnName = item;

                }
                else if(item == "Date")
                {
                    //get the proper date format
                    //FillDateFormatToColumn(tblCloned);
                    tblCloned.Columns[i].DataType = typeof(DateTime);
                    tblCloned.Columns[i].ColumnName = item;
                }

                i++;
            }

            tblCloned.AcceptChanges();


            foreach (DataRow row in tblDataTable.Rows)
            {                   
                tblCloned.ImportRow(row);
            }

            tblCloned.AcceptChanges();

            #endregion

in the second foreach loop when it calls to import data to cloned table it adds empty rows.

After couple of tries I came up with this solution which is working:

 foreach (DataRow row in tblDataTable.Rows)
            {
                int x = 0;
                DataRow dr = tblCloned.NewRow();

                foreach (DataColumn dt in tblCloned.Columns)
                {
                    dr[x] = row[x];
                    x++;
                }                       

                tblCloned.Rows.Add(dr);
                //tblCloned.ImportRow(row);
            }

but I will accept Scottie’s answer because it is less code after all.

  • 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-06T10:53:48+00:00Added an answer on June 6, 2026 at 10:53 am

    Instead of

    foreach (DataRow row in tblDataTable.Rows)
    {                   
      tblCloned.ImportRow(row);
    }
    

    try

    foreach (DataRow row in tblDataTable.Rows)
    {                   
      tblCloned.LoadDataRow(row.ItemArray, true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some difficulty with importing data from a .csv file. I am
I am importing some data from an file (xls, csv, xml) wich will result
I'm importing some data from a CSV file, and numbers that are larger than
I have some questions about importing data from Excel/CSV File into SQL Server. Let
I am importing data from a CSV file. One of the fields has an
I'm importing data from a CSV file that comes from excel, but i can't
I have a web form used for importing data from a CSV file. It
I've imported some data from a CSV file in matlab. They are time series
I am importing data from a CSV file using fgetcsv(), which yields an array
I'm trying to import some data (using oracle sql developer) from a .csv file

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.