CSV Files

  • Thread starter Thread starter scorpion53061
  • Start date Start date
S

scorpion53061

I need to write a dataset to a csv file.

It is my understanding a user who does not have excel on their machine can
still work with csv files. Let me know fi that is mistaken.

I need to write a dataset to a csv file. This file would be uploaded to a
ftp server eventually. I need a tutorial on this.

Thank you for your help..
 
Hi Scorpion,

You know that not every CSV file is the same and that (what will for you
probably be no problem) it is very culture dependend.

An you now the statement dataset.writeXML that makes for you an XML file in
one line and is the same easy to read.

In addition I am sure I have made once special this sample for you, and that
I could not make in the time you posted the message and I give you the
answer

:-)

Cor

\\\
Dim Scorpion As New ArrayList
For i As Integer = 0 To ds.Tables("scorpion").Rows.Count - 1
Dim row As New System.Text.StringBuilder
Scorpion.Add(row)
row.append("""")
For y As Integer = 0 To ds.Tables("scorpion").Columns.Count - 1
row.Append(ds.Tables("scorpion").Rows(i)(y).tostring)
If y <> ds.Tables("scorpion").Columns.Count - 1 Then
row.Append(""",""")
' if you want it with a tab
' row.Append("""")
' row.Append(chr(09))
' row.Append("""")
else
row.Append("""")
End If
Next
Next
Dim sw As New IO.StreamWriter("C:\test1\Scorpion.csv")
For i As Integer = 0 To Scorpion.Count - 1
sw.WriteLine(Scorpion(i).ToString)
Next
sw.Flush()
sw.Close()
///

Cor
 
Now Cor do not concern yourself with that.

Feel free to show me the way :)

will the dataset.writexml idea allow users who need to open the file in
excel or notepad be able to deal with it okay?
 
I need to write a dataset to a csv file.
It is my understanding a user who does not have excel on their machine can
still work with csv files. Let me know fi that is mistaken.

I need to write a dataset to a csv file. This file would be uploaded to a
ftp server eventually. I need a tutorial on this.


A csv file is just a plain text file...... If you know how to work with text
files in VB and how to use a dataset, you already know all there is to know.

A "standard" csv file will be like this:

header1, header2, header3
0,1,1
2,1,4
5,16
....

There's the same number of values on each line, and the first line is for
headers while consequent lines contain the values....... Simple as that

Of course if some of the values are strings which can contain comas then you
need to use another char (excel supports pretty much any char but a comon
one that's now more standard than the coma is ;)

In other words reading or writing CSV files in VB is extremely trivial.....

Alex.
 
Hi Scorpion,

Not in the older Excel versions.

However you can try, it is so simple

Everywhere where you have a dataset in your program you can write.
datasetname.writeXML("C:\myDataset.xml")

That is all.

Cor
 
Back
Top