Read CSV into GridView

L

Lelle

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/tutorials/ASPNET2/ASPNET03/aspnet03-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
 
G

Guest

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
(e-mail address removed)
 
L

Lelle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Match/ Merge columns 1
IIF statement 3

Top