Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / January 2006

Tip: Looking for answers? Try searching our database.

Problem on reading .csv files using OleDbConnection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ray - 19 Jan 2006 04:18 GMT
Hi All

I've tried to read a .csv file and bind the data to a datagrid.
I am doing sth like this:

     conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"+
      "Data Source=" + csvPath + ";" +
      "Extended Properties=\"text;HDR=YES;FMT=Delimited\"");
   conn.Open();
      //Read all data into a data table
      OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM ["+csvPath+"]", conn);

But I discover that some of data can not be retrieved (while I can retrieve most of them).
Then when I tried to add a link break (simply pressing Enter) @ the line above the line containing unretrieved value in the text editor, I will get things all right.

I guess it is sth to do with the carriage return encoding in the CSV (CSV provided by the others), so that the conn can't recognize the string, how can I fix that?

Thanks

Ray
Cor Ligthert [MVP] - 19 Jan 2006 06:02 GMT
Ray,

Are you sure that the CSV is confirm your local settings of your system.

There is not one standard CSV format on the world.

Cor
Milosz Skalecki - 19 Jan 2006 11:10 GMT
> Hi All
>
[quoted text clipped - 7 lines]
>        //Read all data into a data table
>        OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM ["+csvPath+"]", conn);

Shouldn't be
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM
["+strFilenameWithoutPath+"]", conn);
?
Signature

Milosz Skalecki
MCP, MCAD

Paul Clement - 19 Jan 2006 15:24 GMT
¤ Hi All
¤
¤ I've tried to read a .csv file and bind the data to a datagrid.
¤ I am doing sth like this:
¤
¤       conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"+
¤        "Data Source=" + csvPath + ";" +
¤        "Extended Properties=\"text;HDR=YES;FMT=Delimited\"");
¤     conn.Open();
¤        //Read all data into a data table
¤        OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM ["+csvPath+"]", conn);
¤
¤ But I discover that some of data can not be retrieved (while I can retrieve most of them).
¤ Then when I tried to add a link break (simply pressing Enter) @ the line above the line containing unretrieved value in the text editor, I will get things all right.
¤
¤ I guess it is sth to do with the carriage return encoding in the CSV (CSV provided by the others), so that the conn can't recognize the string, how can I fix that?

If the file is missing end-of-line characters then I'm afraid the only way to handle this is to fix
the file. I don't know of any way to compensate for this in the connection string or a schema.ini
file.

Paul
~~~~
Microsoft MVP (Visual Basic)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.