473,387 Members | 1,379 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,387 software developers and data experts.

Retaining a Comma when writing to a CSV

I am writing a console app in c# wherein am converting a dataset into a CSV
file. It works fine. But I have some values in the dataset which have a comma
within(eg. A,B,C). When I view the CSV file in Excel, the multiple values
which are separated by the 'comma' in the dataset are being displayed in the
next column , which I dont want that way. I want to retain any commas which
are present in my dataset.
How do I handle such a scenario?

Thanks
Deepa
Jul 21 '05 #1
8 5686
You could do a couple things. If you put quotes around your text (called
text qualifier), "A,B,C" then Excel will ignore the commas within the
quotes. Another choice is to use a deliminator other than a comma, such as
a TAB or a pipe.

Kevin

"Deepa" <De***@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.com...
I am writing a console app in c# wherein am converting a dataset into a CSV
file. It works fine. But I have some values in the dataset which have a
comma
within(eg. A,B,C). When I view the CSV file in Excel, the multiple values
which are separated by the 'comma' in the dataset are being displayed in
the
next column , which I dont want that way. I want to retain any commas
which
are present in my dataset.
How do I handle such a scenario?

Thanks
Deepa

Jul 21 '05 #2
Kevin
I tried using the tab and the pipe delimiters but the resulting output file
when viewed in excel isnt the same as i want it.(similar to a csv).
I thought of the double quotes but am not able to figure out how I write the
code to see what values in the dataset have a comma or not.
Would appreciate a response to this.

Thanks
Deepa

"Kevin Thomas" wrote:
You could do a couple things. If you put quotes around your text (called
text qualifier), "A,B,C" then Excel will ignore the commas within the
quotes. Another choice is to use a deliminator other than a comma, such as
a TAB or a pipe.

Kevin

"Deepa" <De***@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.com...
I am writing a console app in c# wherein am converting a dataset into a CSV
file. It works fine. But I have some values in the dataset which have a
comma
within(eg. A,B,C). When I view the CSV file in Excel, the multiple values
which are separated by the 'comma' in the dataset are being displayed in
the
next column , which I dont want that way. I want to retain any commas
which
are present in my dataset.
How do I handle such a scenario?

Thanks
Deepa


Jul 21 '05 #3
You don't have to worry about which values have a comma or not. If the
field is a text field (or you want it treated as such by Excel) just enclose
it in quotes. You might have a row that ends up looking like:

"abcdef", "23klk,23,23", "eeeejjj","eee,t,r", 9,5

So you see, you put quotes around all your text fields. If one ends up with
a comma in it, Excel will ignore it because it's in quotes.

Kev

"Deepa" <De***@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.com...
Kevin
I tried using the tab and the pipe delimiters but the resulting output
file
when viewed in excel isnt the same as i want it.(similar to a csv).
I thought of the double quotes but am not able to figure out how I write
the
code to see what values in the dataset have a comma or not.
Would appreciate a response to this.

Thanks
Deepa

"Kevin Thomas" wrote:
You could do a couple things. If you put quotes around your text (called
text qualifier), "A,B,C" then Excel will ignore the commas within the
quotes. Another choice is to use a deliminator other than a comma, such
as
a TAB or a pipe.

Kevin

"Deepa" <De***@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.com...
>I am writing a console app in c# wherein am converting a dataset into a
>CSV
> file. It works fine. But I have some values in the dataset which have a
> comma
> within(eg. A,B,C). When I view the CSV file in Excel, the multiple
> values
> which are separated by the 'comma' in the dataset are being displayed
> in
> the
> next column , which I dont want that way. I want to retain any commas
> which
> are present in my dataset.
> How do I handle such a scenario?
>
> Thanks
> Deepa


Jul 21 '05 #4
Thanks dude. Just curious if you can help me with something else.
I have this dataset am converting into a csv file. Before I write to the
output.csv I want to sort the values of the dataset in ascending order. I
just have one single table in my dataset. I have the dataset ready, i mean to
say am not making any connection to the database to populate the dataset. I
have it as an xml dataset file. And am just saying ds.ReadXml(the xml file
path)
Before I loop thru the dataset, I want to sort it.
Any ideas?

thanks
Deepa

"Kevin Thomas" wrote:
You don't have to worry about which values have a comma or not. If the
field is a text field (or you want it treated as such by Excel) just enclose
it in quotes. You might have a row that ends up looking like:

"abcdef", "23klk,23,23", "eeeejjj","eee,t,r", 9,5

So you see, you put quotes around all your text fields. If one ends up with
a comma in it, Excel will ignore it because it's in quotes.

Kev

"Deepa" <De***@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.com...
Kevin
I tried using the tab and the pipe delimiters but the resulting output
file
when viewed in excel isnt the same as i want it.(similar to a csv).
I thought of the double quotes but am not able to figure out how I write
the
code to see what values in the dataset have a comma or not.
Would appreciate a response to this.

Thanks
Deepa

"Kevin Thomas" wrote:
You could do a couple things. If you put quotes around your text (called
text qualifier), "A,B,C" then Excel will ignore the commas within the
quotes. Another choice is to use a deliminator other than a comma, such
as
a TAB or a pipe.

Kevin

"Deepa" <De***@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.com...
>I am writing a console app in c# wherein am converting a dataset into a
>CSV
> file. It works fine. But I have some values in the dataset which have a
> comma
> within(eg. A,B,C). When I view the CSV file in Excel, the multiple
> values
> which are separated by the 'comma' in the dataset are being displayed
> in
> the
> next column , which I dont want that way. I want to retain any commas
> which
> are present in my dataset.
> How do I handle such a scenario?
>
> Thanks
> Deepa


Jul 21 '05 #5
Well if your DataTable is in a Dataset with no other tables, then it would
look something like this:

myDataset.tables[0].DefaultView.Sort = "Name Of Column You Want To Sort By"

See if that works for ya.

See this article for more info:
http://msdn.microsoft.com/library/de...tviewtopic.asp

Kevin

"Deepa" <De***@discussions.microsoft.com> wrote in message
news:FB**********************************@microsof t.com...
Thanks dude. Just curious if you can help me with something else.
I have this dataset am converting into a csv file. Before I write to the
output.csv I want to sort the values of the dataset in ascending order. I
just have one single table in my dataset. I have the dataset ready, i mean
to
say am not making any connection to the database to populate the dataset.
I
have it as an xml dataset file. And am just saying ds.ReadXml(the xml file
path)
Before I loop thru the dataset, I want to sort it.
Any ideas?

thanks
Deepa

"Kevin Thomas" wrote:
You don't have to worry about which values have a comma or not. If the
field is a text field (or you want it treated as such by Excel) just
enclose
it in quotes. You might have a row that ends up looking like:

"abcdef", "23klk,23,23", "eeeejjj","eee,t,r", 9,5

So you see, you put quotes around all your text fields. If one ends up
with
a comma in it, Excel will ignore it because it's in quotes.

Kev

"Deepa" <De***@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.com...
> Kevin
> I tried using the tab and the pipe delimiters but the resulting output
> file
> when viewed in excel isnt the same as i want it.(similar to a csv).
> I thought of the double quotes but am not able to figure out how I
> write
> the
> code to see what values in the dataset have a comma or not.
> Would appreciate a response to this.
>
> Thanks
> Deepa
>
> "Kevin Thomas" wrote:
>
>> You could do a couple things. If you put quotes around your text
>> (called
>> text qualifier), "A,B,C" then Excel will ignore the commas within the
>> quotes. Another choice is to use a deliminator other than a comma,
>> such
>> as
>> a TAB or a pipe.
>>
>> Kevin
>>
>> "Deepa" <De***@discussions.microsoft.com> wrote in message
>> news:16**********************************@microsof t.com...
>> >I am writing a console app in c# wherein am converting a dataset into
>> >a
>> >CSV
>> > file. It works fine. But I have some values in the dataset which
>> > have a
>> > comma
>> > within(eg. A,B,C). When I view the CSV file in Excel, the multiple
>> > values
>> > which are separated by the 'comma' in the dataset are being
>> > displayed
>> > in
>> > the
>> > next column , which I dont want that way. I want to retain any
>> > commas
>> > which
>> > are present in my dataset.
>> > How do I handle such a scenario?
>> >
>> > Thanks
>> > Deepa
>>
>>
>>


Jul 21 '05 #6
On Fri, 11 Mar 2005 12:03:04 -0800, "Deepa"
<De***@discussions.microsoft.com> wrote:
I am writing a console app in c# wherein am converting a dataset into a CSV
file. It works fine. But I have some values in the dataset which have a comma
within(eg. A,B,C). When I view the CSV file in Excel, the multiple values
which are separated by the 'comma' in the dataset are being displayed in the
next column , which I dont want that way. I want to retain any commas which
are present in my dataset.
How do I handle such a scenario?

Thanks
Deepa


For all you ever wanted to know about CSV files, have a look at
http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm

rossum
--

The ultimate truth is that there is no Ultimate Truth
Jul 21 '05 #7
You forgot to mention what to do when there's quotes in the data. You'd
need to double them up as an escape.

The other option is to use my csv parser,
http://www.geocities.com/shriop/index.html , or one like it, which
handles all of this for you and can write all data directly from a
DataTable.

Jul 21 '05 #8
Thanks Kevin,will try doing that

"Kevin Thomas" wrote:
Well if your DataTable is in a Dataset with no other tables, then it would
look something like this:

myDataset.tables[0].DefaultView.Sort = "Name Of Column You Want To Sort By"

See if that works for ya.

See this article for more info:
http://msdn.microsoft.com/library/de...tviewtopic.asp

Kevin

"Deepa" <De***@discussions.microsoft.com> wrote in message
news:FB**********************************@microsof t.com...
Thanks dude. Just curious if you can help me with something else.
I have this dataset am converting into a csv file. Before I write to the
output.csv I want to sort the values of the dataset in ascending order. I
just have one single table in my dataset. I have the dataset ready, i mean
to
say am not making any connection to the database to populate the dataset.
I
have it as an xml dataset file. And am just saying ds.ReadXml(the xml file
path)
Before I loop thru the dataset, I want to sort it.
Any ideas?

thanks
Deepa

"Kevin Thomas" wrote:
You don't have to worry about which values have a comma or not. If the
field is a text field (or you want it treated as such by Excel) just
enclose
it in quotes. You might have a row that ends up looking like:

"abcdef", "23klk,23,23", "eeeejjj","eee,t,r", 9,5

So you see, you put quotes around all your text fields. If one ends up
with
a comma in it, Excel will ignore it because it's in quotes.

Kev

"Deepa" <De***@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.com...
> Kevin
> I tried using the tab and the pipe delimiters but the resulting output
> file
> when viewed in excel isnt the same as i want it.(similar to a csv).
> I thought of the double quotes but am not able to figure out how I
> write
> the
> code to see what values in the dataset have a comma or not.
> Would appreciate a response to this.
>
> Thanks
> Deepa
>
> "Kevin Thomas" wrote:
>
>> You could do a couple things. If you put quotes around your text
>> (called
>> text qualifier), "A,B,C" then Excel will ignore the commas within the
>> quotes. Another choice is to use a deliminator other than a comma,
>> such
>> as
>> a TAB or a pipe.
>>
>> Kevin
>>
>> "Deepa" <De***@discussions.microsoft.com> wrote in message
>> news:16**********************************@microsof t.com...
>> >I am writing a console app in c# wherein am converting a dataset into
>> >a
>> >CSV
>> > file. It works fine. But I have some values in the dataset which
>> > have a
>> > comma
>> > within(eg. A,B,C). When I view the CSV file in Excel, the multiple
>> > values
>> > which are separated by the 'comma' in the dataset are being
>> > displayed
>> > in
>> > the
>> > next column , which I dont want that way. I want to retain any
>> > commas
>> > which
>> > are present in my dataset.
>> > How do I handle such a scenario?
>> >
>> > Thanks
>> > Deepa
>>
>>
>>


Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jack | last post by:
Hi, I have form where one has to input officer's salary along with other data. The officer's salary field is tied to a currency field in backend Access. Right now folks enter numbers e.g....
5
by: Yama | last post by:
Hi, I am looking to create a report comma delimited on a click of a button. Explanantion: 1. Get from the database: "SELECT * FROM Customers WHERE Region = 'CA'" 2. Use either DataReader or...
8
by: Deepa | last post by:
I am writing a console app in c# wherein am converting a dataset into a CSV file. It works fine. But I have some values in the dataset which have a comma within(eg. A,B,C). When I view the CSV file...
14
by: bonehead | last post by:
Greetings, I'm using the DoCmd.TransferText method to export the results of a MS Access query to a csv file. The csv will then be used to load an Oracle table. In other systems such as TOAD...
3
by: Avi | last post by:
I need to create a text file that has the data from the 10 tables in the database. The number of fields in the tables exceeds 255 and so I cannot make a new table with all the fields and then...
4
by: =?Utf-8?B?RXJpY2E=?= | last post by:
I am trying to dynamically create a javascript link. But, I get the following error: BC32017: Comma, ')', or a valid expression continuation expected. Here is the line I try creating the...
2
by: Matthias Neubauer | last post by:
Hi! I am a C++ newbie and I'd like to trace the evaluation of some expressions of my programs. I tried to use the comma operator for that, but failed. I used a simple code substitution for...
2
by: s4lin | last post by:
problem is pagination not retaining data field i have form with general data field, and i need to select some option which is store in database, so i open another page with retrieving data from...
3
by: nigel | last post by:
Hi, I'm using VBA to export data from a table direct to a CSV file DoCmd.TransferText acExportDelim, , "ExportTable", filePath this produced a file with COMMA separated values,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.