Re: How to connect to .CSV file ?
- From: adi suciu <suciu_adrian@xxxxxxxxxx>
- Date: Wed, 11 Oct 2006 04:44:07 +0300
fniles wrote:
I have a .CSV file (comma delimited) that I want to open using OLEDB, but I get the error "External table is not in the expected format."
If I save the .CSV file to an .XLS file, I can open the connection with no problem.
What is the correct way to open a .CSV file ?
If I can not open the CSV file, how can I programmatically save the CSV file to an XLS file ?
Thanks a lot.
dim myCon OleDb.OleDbConnection
myCon = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\file.csv; Extended Properties=""Excel 8.0; HDR=NO; IMEX=1""")
--> error "External table is not in the expected format."
Hello,
A very simple way to open and read the contents of a *.CSV file is with System.IO.StreamReader.
Let me show you an example in C#:
// You first create a StreamReader to read the file
System.IO.StreamReader myReader = new System.IO.StreamReader("c:\\myFile.csv");
//Let say you want to store all the read contents into a string variable
string myString;
//test if the reader had reached the end of the stream or not
while (myReader.Peek != -1)
{
/*
Here you will have each line of string read from the file put int-o the myString variable. You can start parse your results into an array, or anything else.
*/
myString = myReader.ReadLine();
}
Hope it will help you.
Have a nice day.
.
- References:
- How to connect to .CSV file ?
- From: fniles
- How to connect to .CSV file ?
- Prev by Date: How to connect to .CSV file ?
- Next by Date: Problem with ADODC.ocx control
- Previous by thread: How to connect to .CSV file ?
- Next by thread: Problem with ADODC.ocx control
- Index(es):
Relevant Pages
|
|