writeto csv file

  • Thread starter Thread starter Mei Qin
  • Start date Start date
M

Mei Qin

Hello,

I have the following code to write each columns in a
datarow to the csv file:
myStreamWriter.Write(chr(34) & (myDr(I).ToString) & chr(34)
& ",")
I have a string field with the value of "000000". When I
open the file in Excel, the value displayed as "0". But I
really need to keep the way it is in the database. I tried
the following:
myStreamWriter.Write(chr(39) & (myDr(I).ToString) & ",")
It displayed as "'000000".
What should I do to display the value correctly in the CSV
file?

Thanks for any help!

Mei
 
Are you sure the actual csv file is being outputted incorrectly? You said you opened it in excel, which will take your 000000 and make it into a 0 (that's just excel's problem), but if the csv file itself is ok, you are good to go. By the way, from a programming standpoint, always open csv files from a text editor, not excel, excel will change it around as you've found out!
 
The customer need to open the CSV file in Excel, so they
can sort, filter on the data.
-----Original Message-----
Are you sure the actual csv file is being outputted
incorrectly? You said you opened it in excel, which will
take your 000000 and make it into a 0 (that's just excel's
problem), but if the csv file itself is ok, you are good
to go. By the way, from a programming standpoint, always
open csv files from a text editor, not excel, excel will
change it around as you've found out!
"Mei Qin" <[email protected]> wrote in
message news:[email protected]...
 
Then in that case, you are probably going to need to surround all text values like this in quotes

"000000", "ABC", 45, 2837
 
Back
Top