Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# OleDb
I am reading a .csv file using C# and OleDb. There are mixed datatypes in one column that consist of ints and doubles. The probelm is that the double values in this column are at the bottom of the file and are read last.
 
I am aware that the datatype for the column is determined by the first 8 rows by default and that it can be changed. I have done everything I can in order to fix this issue and none of them work. The only thing that made it work was to move the data from the bottom to the top so that the double would be read, but I cannot have that as a solution.
 
I have used the schema.ini file, changed the TypeGuessRow in the registry, and have IMEX=1 in my extended properties of the provider. Does anyone have any other ideas or maybe a topic I can search?
Posted 4-Feb-13 5:16am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Forget OleDb and look at LINQ.
There are a few great articles here regarding parsing CSV files with LINQ, after a quick search this is the best one i found: LINQ to CSV library[^]
  Permalink  
Comments
richcb at 6-Feb-13 11:44am
   
I attempted to utilize this method and was not successful. I am sure it works, I just did not have any luck or implemented it wrong. Thank you for that suggestion, I will accept it as an answer anyway.
Adam R Harris at 6-Feb-13 12:08pm
   
If you can post a sample and an error i might be able to help out.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I ended using a custom method to read the .csv file. It read the data into a string[] list. I then parsed the list to do what I needed to do with the data. Here is the method I used:
 
 public List<string[]> parseCSV(string path)
    {
        List<string[]> parsedData = new List<string[]>();
        try
        {
            using (StreamReader readFile = new StreamReader(path))
            {
                string line;
                string[] row;
 
                while ((line = readFile.ReadLine()) != null)
                {
                    row = line.Split(',');
                    parsedData.Add(row);
                }
            }
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }
 
        return parsedData;
    }
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 230
2 BillWoodruff 205
3 Sergey Alexandrovich Kryukov 195
4 DamithSL 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100