473,224 Members | 1,976 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,224 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 5672
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,...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.