Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am struggling to find good information how to query data from a CSV file.

I have to query the CSV file to generate reports and then run in the console.

Can anyone help?

These are the fields that I am using below.

Customer Information

Forename
Surname
Date of Birth

Vehicle Information

Manufacturer
Model
Registration number
Registration date
Engine size (in cc)

Owner

InteriorColour (Car only)
Has Helmet Storage (Motorcycle only)
Required Relationships
Customers can have 1 to many vehicles.
Vehicle must have exactly one owner.
Vehicle type cannot be changed once it is created.

Reports

We will require reports to be designed to contain:
All known customers and any vehicles they own.
All customers between the age of 20 and 30.
All Vehicles registered before 1st January 2010.
All Vehicles with an engine size over 1100.

What I have tried:

Displaying the CSV file in the console

C#
using System;
using System.IO;

namespace PinewoodTest
{
    class Class1
    {
        static void Main(string[] args)
        {
            try
            {
                String st = File.ReadAllText("/Users/thomasjeffcock/Projects/PinewoodTest/CustomerInformation.csv");
                Console.WriteLine(st);
            }
            catch(Exception e)
            {
                Console.WriteLine("The File Could Not Be Read");
                Console.WriteLine(e.Message);
            } 

            Console.Read();
        }
    }
}
Posted
Updated 15-Mar-18 1:40am
Comments
PIEBALDconsult 14-Mar-18 20:02pm    
I use the OleDb classes in ADO.net with the ACE Engine.
Karthik_Mahalingam 14-Mar-18 23:36pm    
show the sample data from csv

I would recommend using CSV helper (add it via NuGet packet manager to your project GitHub - JoshClose/CsvHelper: Library to help reading and writing CSV files[^] to read data from file. Create collection (List for example) of queryable objects (define your type) and then use Linq to find, sort and order the information.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900