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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:57:51+00:00 2026-05-14T02:57:51+00:00

I currently have a csv file that I’m parsing with an example from here:

  • 0

I currently have a csv file that I’m parsing with an example from here:
http://alexreg.wordpress.com/2009/05/03/strongly-typed-csv-reader-in-c/

I then want to loop the records and insert them using a typed dataset xsd to an Oracle database.

It’s not that difficult, something like:

foreach (var csvItem in csvfile)
{
   DataSet.MYTABLEDataTable DT = new DataSet.MYTABLEDataTable();
   DataSet.MYTABLERow row = DT.NewMYTABLERow();
   row.FIELD1 = csvItem.FIELD1;
   row.FIELD2 = csvItem.FIELD2;
}

I was wondering how I would do something with LINQ projection:

var test = from csvItem in csvfile
  select new MYTABLERow {
    FIELD1 = csvItem.FIELD1,
    FIELD2 = csvItem.FIELD2
}

But I don’t think I can create datarows like this without the use of a rowbuilder, or maybe a better constructor for the datarow?

  • 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-14T02:57:52+00:00Added an answer on May 14, 2026 at 2:57 am

    You could, but you shouldn’t. NewRow() is a method, not a constructor that allows for an object initializer to be used. You’re better off sticking with the foreach loop for clarity.

    You can abuse LINQ to pull this off, but this is not recommended and is for demonstration purposes only:

    DataTable dt = new DataTable();
    dt.Columns.Add("Id", typeof(int));
    dt.Columns.Add("Customer", typeof(string));
    dt.Rows.Add(new Object[] { 24, "Peter Parker" });
    dt.Rows.Add(new Object[] { 42, "Bruce Wayne" });
    
    var query = Enumerable.Range(1, 5).All(i =>
                {
                    var row = dt.NewRow();
                    row["Id"] = i;
                    row[1] = "Customer" + i;
                    dt.Rows.Add(row);
                    return true;
                });
    
    foreach (DataRow row in dt.Rows)
    {
        Console.WriteLine("{0}: {1}", row[0], row[1]);
    }
    

    The idea is to use a lambda statement to do your work. Notice you gain nothing and the statements are going to be identical to what you had in the foreach loop. On top of that, LINQ is deferred, so the rows are never added until the query is iterated over. In the snippet above I forced this to be immediate by using the All method and returning true for each item so all items continue to be processed. In fact the var query = bit can be removed since it’s not used.

    In your case your source would be the csvfile:

    csvfile.All(csvItem => { /* do work here */ });
    

    This approach introduces side effects since the LINQ query isn’t used for its original intent. LINQ is for querying. You might also find Eric Lippert’s post helpful: “foreach” vs “ForEach”.

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

Sidebar

Related Questions

I have a csv file that I will be regularly updating through a batch
I have created a solution which read a large csv file currently 20-30 mb
I currently have a report that give me the users ID number and their
I am trying to load a CSV file into an array using ColdFusion (version
We have pretty large files, the order of 1-1.5 GB combined (mostly log files)
I have a process users must go through on my site which can take
Internally our PHP application uses UTF-8, and we do processing on .csv files and
I'm trying to load a CSV into a DataTable using this: class CSVReader {
Almost 6 months ago, I asked a question on stackoverflow Software to help in
I am new to perl so please accept my apologies if my question is

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.