473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Read CSV into GridView

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
3 1703
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
0
by: Hongbo | last post by:
Hi, I have a GridView like this one: == <asp:gridview runat="server" id="gvCategory" allowpaging="true" allowsorting="true" alternatingrowstyle-backcolor="#B9DFC7" autogeneratecolumns="false" ...
0
by: Michael Kellogg | last post by:
I have a problem wherein a query that updates a GridView doesn't seem to really stay in sync with a label I have above the GridView. I have a GridView object that I'm updating with information...
1
by: hal | last post by:
Hello All, I have a windows form with a gridview control and i'm trying to get the gridview to read the entire XML file. Anyone have any ideas on how to do this? Below is some code so you can...
2
by: dba123 | last post by:
I need help in coding the following or if you can just point me in the right direction: 1) Reading the follwoing XML document 2) Hook up a GridView to the data received from the XML document. ...
2
by: cartmann | last post by:
Hi, I have a gridview with a template column. In the template column i have two commandbuttons. When clicking the buttons I enter the cmd_click event - but how do I read in which row the button...
0
by: ballamber | last post by:
This is a solution to the problem. Works with .NET 2.0. So the problem is displaying a data bound read-only checkbox or radio button in a GridView without actually disabling those controls. I...
0
by: ntuyen01 | last post by:
Hi All, I try to read the data from the excel, but I ran into this problem I have two excel files. file one.xls data inside like this: 1234 1234 1234 1234 abc-123 ...
3
by: Mel | last post by:
How do I open an Excel file as a read only document? It would be okay if it opened in the browser window but I don't want the user to save any changes and stomp over my original file on the...
1
BeemerBiker
by: BeemerBiker | last post by:
I converted an arraylist to a dataset and bound the dataset to a gridview but I cannot change the value of the checkbox in the gridview. I identified the DataKeyNames and made sure that ReadOnly was...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.