By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,369 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,369 IT Pros & Developers. It's quick & easy.

Read CSV into GridView

P: n/a
hello!

how can i read a csv file with this syntax into my gridview?

SSN","First Name","Last Name","Salary","Department
111-11-1111","Ann","Adams","60000.00","Accounting
222-22-2222","Beth","Baker","55000.00","Marketing
333-33-3333","Cecil","Carelton","61000.00","Information Technology
444-44-4444","David","Davis","63000.00","Information Technology
555-55-5555","Ellen","Edwards","65000.00","Accounting
i have tried this
http://msconline.maconstate.edu/tuto...pnet03-06.aspx

but when i have the "," in the textfile i only gets the first column, if i
dont have the "," just a comma as delimiter then i gets the whole file in
the same column

/ Lelle

Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Lelle,

Following code snippet let you easily replace '","' to ',' in a file:

System.IO.StreamReader fr = new System.IO.StreamReader(filePath);
string data = fr.ReadToEnd();
fr.Close();
string replaceString = "\",\"";
data = data.Replace(replaceString, ",");
System.IO.StreamWriter fw = new System.IO.StreamWriter(filePath,false);
fw.Write(data);
fw.Close();

HTH

Elton Wang
el********@hotmail.com

"Lelle" wrote:
hello!

how can i read a csv file with this syntax into my gridview?

SSN","First Name","Last Name","Salary","Department
111-11-1111","Ann","Adams","60000.00","Accounting
222-22-2222","Beth","Baker","55000.00","Marketing
333-33-3333","Cecil","Carelton","61000.00","Information Technology
444-44-4444","David","Davis","63000.00","Information Technology
555-55-5555","Ellen","Edwards","65000.00","Accounting
i have tried this
http://msconline.maconstate.edu/tuto...pnet03-06.aspx

but when i have the "," in the textfile i only gets the first column, if i
dont have the "," just a comma as delimiter then i gets the whole file in
the same column

/ Lelle

Nov 19 '05 #2

P: n/a
I would suggest you try my csv parser.
http://www.geocities.com/shriop/index.html The ReadToEnd method will
return a DataTable with the contents of the csv file that you can then
use to set the DataSource of the DataView.

Elton W wrote:
Hi Lelle,

Following code snippet let you easily replace '","' to ',' in a file:

System.IO.StreamReader fr = new System.IO.StreamReader(filePath);
string data = fr.ReadToEnd();
fr.Close();
string replaceString = "\",\"";
data = data.Replace(replaceString, ",");
System.IO.StreamWriter fw = new System.IO.StreamWriter(filePath,false);
fw.Write(data);
fw.Close();

HTH

Elton Wang
el********@hotmail.com

"Lelle" wrote:
hello!

how can i read a csv file with this syntax into my gridview?

SSN","First Name","Last Name","Salary","Department
111-11-1111","Ann","Adams","60000.00","Accounting
222-22-2222","Beth","Baker","55000.00","Marketing
333-33-3333","Cecil","Carelton","61000.00","Information Technology
444-44-4444","David","Davis","63000.00","Information Technology
555-55-5555","Ellen","Edwards","65000.00","Accounting
i have tried this
http://msconline.maconstate.edu/tuto...pnet03-06.aspx

but when i have the "," in the textfile i only gets the first column, if i
dont have the "," just a comma as delimiter then i gets the whole file in
the same column

/ Lelle


Nov 19 '05 #3

P: n/a
thanks for your answer elton
if i remove the "," and use just a , then i gets all data in one column just
like this

SSN,First Name,Last Name,Salary,Department
111-11-1111,Ann,Adams,60000.00,Accounting
222-22-2222,Beth,Baker,55000.00,Marketing
333-33-3333,Cecil,Carelton,61000.00,Information Technology
444-44-4444,David,Davis,63000.00,Information Technology
555-55-5555,Ellen,Edwards,65000.00,Accounting
i want it to look like this SSN First Name Last Name Salary Department
111-11-1111 Ann Adams 60000 Accounting 222-22-2222 Beth Baker 55000
Marketing 333-33-3333 Cecil Carelton 61000 Information Technology
444-44-4444 David Davis 63000 Information Technology 555-55-5555 Ellen
Edwards 65000 Accounting

"Elton W" <El****@discussions.microsoft.com> skrev i meddelandet
news:D9**********************************@microsof t.com...
Hi Lelle,

Following code snippet let you easily replace '","' to ',' in a file:

System.IO.StreamReader fr = new System.IO.StreamReader(filePath);
string data = fr.ReadToEnd();
fr.Close();
string replaceString = "\",\"";
data = data.Replace(replaceString, ",");
System.IO.StreamWriter fw = new System.IO.StreamWriter(filePath,false);
fw.Write(data);
fw.Close();

HTH

Elton Wang
el********@hotmail.com

"Lelle" wrote:
hello!

how can i read a csv file with this syntax into my gridview?

SSN","First Name","Last Name","Salary","Department
111-11-1111","Ann","Adams","60000.00","Accounting
222-22-2222","Beth","Baker","55000.00","Marketing
333-33-3333","Cecil","Carelton","61000.00","Information Technology
444-44-4444","David","Davis","63000.00","Information Technology
555-55-5555","Ellen","Edwards","65000.00","Accounting
i have tried this
http://msconline.maconstate.edu/tuto...pnet03-06.aspx

but when i have the "," in the textfile i only gets the first column, if
i
dont have the "," just a comma as delimiter then i gets the whole file in
the same column

/ Lelle

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.