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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:19:32+00:00 2026-06-12T22:19:32+00:00

I have a csv file I am going to read from disk. I do

  • 0

I have a csv file I am going to read from disk. I do not know up front how many columns or the names of the columns.
Any thoughts on how I should represent the fields. Ideally I want to say something like,

string Val = DataStructure.GetValue(i,ColumnName).
where i is the ith Row.

Oh just as an aside I will be parsing using the TextFieldParser class
http://msdn.microsoft.com/en-us/library/cakac7e6(v=vs.90).aspx

  • 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-12T22:19:33+00:00Added an answer on June 12, 2026 at 10:19 pm

    That sounds as if you would need a DataTable which has a Rows and Columns property.

    So you can say:

    string Val = table.Rows[i].Field<string>(ColumnName);
    

    A DataTable is a table of in-memory data. It can be used strongly typed (as suggested with the Field method) but actually it stores it’s data as objects internally.

    You could use this parser to convert the csv to a DataTable.

    Edit: I’ve only just seen that you want to use the TextFieldParser. Here’s a possible simple approach to convert a csv to a DataTable:

    var table = new DataTable();
    using (var parser = new TextFieldParser(File.OpenRead(path)))
    {
        parser.Delimiters = new[]{","};
        parser.HasFieldsEnclosedInQuotes = true;
        // load DataColumns from first line 
        String[] headers = parser.ReadFields();
        foreach(var h in headers)
                table.Columns.Add(h);
        // load all other lines as data '
        String[] fields;
        while ((fields = parser.ReadFields()) != null)
        {
            table.Rows.Add().ItemArray = fields;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have csv files, java app and database, i read csv file from my
I have .csv file that contain 2 columns delimited with , . file.csv word1,word2
How to read and import .csv file in groovy on grails. I have .csv
I have a CSV file supplied from a client which has to be parsed
I have a csv file with 5 columns. I want to fetch the row
I have a CSV file the first row of which contains the variables names
I have a CSV file with 5 columns and about 2*10 4 rows that
I have a JSON file that was converted from a csv and is too
I have CSV file and Macro in VBA. I want to open CSV file
Little Background: I have csv file which has lots of rows and each row

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.