3
Answers

Parse csv

Udi Goldstein

Udi Goldstein

13y
1.6k
1
Hi,

I'm trying to parse a csv file using a code i've found on line:


{


private DataTable ParseCSV(string path)if (!File.Exists(path))return null;string full = Path.GetFullPath(path);string file = Path.GetFileName(full);string dir = Path.GetDirectoryName(full);//create the "database" connection string

string connString = "Provider=Microsoft.Jet.OLEDB.4.0;"+
"Data Source=\"" + dir + "\\\";"+



"Extended Properties=\"text;HDR=No;FMT=Delimited(=)\"";//create the database query



string query = "SELECT * FROM " + file;//create a DataTable to hold the query results



DataTable dTable = new DataTable();//create an OleDbDataAdapter to execute the query



OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);try{


//fill the DataTabledAdapter.Fill(dTable);
}


{ }
dAdapter.Dispose();
dataGridView1.DataSource = dTable;


}
catch (InvalidOperationException /*e*/)return dTable;


Only problem is that my delimiter is an equal sign (=), and the code doesn't delimit it even though i tried to put the equal sign. I just get one column with the undelimited data, instead of two seperate columns.

Why is this happening? is there a solution for that? or is there other way of parsing csv right?
Answers (3)