Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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[^]
 
Share this answer
 
Comments
Richard C Bishop 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 6-Feb-13 12:08pm    
If you can post a sample and an error i might be able to help out.
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;
   }
 
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