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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:41:31+00:00 2026-05-24T04:41:31+00:00

I follow the tutorial here to query content from CSV file: http://rudesyle.wordpress.com/2008/01/28/using-linq-to-query-a-csv-file/ However, the

  • 0

I follow the tutorial here to query content from CSV file:
http://rudesyle.wordpress.com/2008/01/28/using-linq-to-query-a-csv-file/

However, the result misses the first row which is
“Mets”,”New York”,”NL”

After some testing, I realize that if I have a empty line at the top of the file, the result is as expected.

Bellow is my code and .csv file

“teams.csv”

"Mets","New York","NL"
"Marlins","Florida","NL"
"Orioles","Baltimore","AL"
"Pirates","Pittsburgh","NL"
"Phillies","Philadelphia","NL"

Program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace CSVQuery
{
    class Program
    {
        static void QueryCsv()
        {

            OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\;Extended Properties='Text;HDR=No;FMT=Delimited'");
            OleDbCommand cmd = new OleDbCommand(@"SELECT * FROM ..\..\teams.csv", cn);
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);

            cn.Open();

            DataTable dt = new DataTable();
            da.Fill(dt);
            var teams = from r in dt.AsEnumerable() where r.Field<string>(2) == "NL"
                            select new { City = r.Field<string>(0),
                            TeamName = r.Field<string>(1) };

            foreach (var team in teams)
            {
                Console.WriteLine(String.Format("The {0} {1}", team.TeamName, team.City));
            }

            Console.ReadLine();

            cn.Close();

        }
        static void Main(string[] args)
        {
            CSVQuery.Program.QueryCsv();
        }
    }
}

Actual result:

The Florida Marlins
The Pittsburgh Pirates
The Philadelphia Phillies

Expected result:

The New York Mets
The Florida Marlins
The Pittsburgh Pirates
The Philadelphia Phillies

The question is that why I can’t query the first line of the teams.csv file? (I need to add 1 empty line at the top so that I can receive expected result).

  • 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-24T04:41:32+00:00Added an answer on May 24, 2026 at 4:41 am

    This post Reading CSV file with OLEDB ignores first line even with HDR=No in Connection String suggests that the problem is because the full path is in the Select string. Try putting the path in the connection string and just put the file name in the Select string. I cannot imagine why this should make a difference, but that is what was suggested over there.

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

Sidebar

Related Questions

Using NPOI and attempting to follow a tutorial here: http://www.zachhunter.com/2010/05/npoi-excel-template/ , I'm coming across
I'm follow this tutorial to use CAPTCHA in MVC application: http://coderjournal.com/2008/03/actionfilterattribute-aspnet-mvc-captcha/ I think this
i am making a sample program in hibernate follow this tutorial: http://www.myeclipseide.com/documentation/quickstarts/hibernateintroduction/ using reverse
I follow tutorial here on how to create web service using RESTful web service
I am trying to follow Trees tutorial at: http://cslibrary.stanford.edu/110/BinaryTrees.html Here is the code I
I'm trying to follow this tutorial about WP7 development: http://mobile.tutsplus.com/tutorials/windows/introduction-to-windows-mobile-7-development/ It's talking about using
i was beggining to follow a tutorial on elementtree in this site http://www.bigfatalien.com/?p=223 so
I am trying to follow a tutorial about xml parsing http://www.edumobile.org/iphone/iphone-programming-tutorials/parsing-an-xml-file/ . The tutorial
I'm attempting to following the tutorials found here: http://www.ifadey.com/2010/06/crud-using-jquery-and-codeigniter/ My code is updated to
This is a follow on question to How do I delete 1 file from

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.