TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Udi Goldstein
NA
22
63.6k
Parse csv
Jul 4 2011 7:09 AM
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 DataTable
dAdapter.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?
Reply
Answers (
3
)
Avoid validation in certain conditions
Print PDF as Image Programmatically in c#