473,480 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Saving a dataset as a comma seperated values file.

Hi,

This must be simple (I hope)! I've tried a google search but can't seem to
find what I want (probably using the wrong search keys!)

I'm trying to simply save a complete dataset as a CSV file so that it can be
easily opened up in Excel or emailed on.

Is there any simple way of doing this, or do I have to write code to scan
through the dataset and write it out line by line to a csv file?

Thanks in advance

Simon
Nov 21 '05 #1
2 1249
Simon,

Scorpion(Kelly) has on his side a page to set it directly to an Excel file.

http://www.kjmsolutions.com/datasetarray.htm

I have this samplecode bellow what is queit generic to set a dataset
datatable to a csv file.

I hope this helps a little bit?

Cor

\\\
Dim sw As New IO.StreamWriter("C:\Whatever.csv")
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
Dim row As New System.Text.StringBuilder
row.Append("""")
For y As Integer = 0 To ds.Tables(0).Columns.Count - 1
row.Append(ds.Tables(0).Rows(i)(y).tostring)
If y <> ds.Tables(0).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
sw.WriteLine(row.ToString)
Next
sw.Flush()
sw.Close()
///
Nov 21 '05 #2
Thanks Cor,

That is pretty much what I thought I would have to do ...

regards
Simon
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OW*************@TK2MSFTNGP12.phx.gbl...
Simon,

Scorpion(Kelly) has on his side a page to set it directly to an Excel file.
http://www.kjmsolutions.com/datasetarray.htm

I have this samplecode bellow what is queit generic to set a dataset
datatable to a csv file.

I hope this helps a little bit?

Cor

\\\
Dim sw As New IO.StreamWriter("C:\Whatever.csv")
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
Dim row As New System.Text.StringBuilder
row.Append("""")
For y As Integer = 0 To ds.Tables(0).Columns.Count - 1
row.Append(ds.Tables(0).Rows(i)(y).tostring)
If y <> ds.Tables(0).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
sw.WriteLine(row.ToString)
Next
sw.Flush()
sw.Close()
///

Nov 21 '05 #3

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

Similar topics

11
2515
by: Craig Keightley | last post by:
I have a mysql database with a list of companies who supply specific products tblSuppliers (simplified) sID | sName | goodsRefs 1 | comp name | 1,2,3,4,5 2 | company 2 | 2,4
0
1214
by: J-T | last post by:
I have a CSV file which contains comma seperated data that I need to validate against our database.I was thinking about loading that CSV file into a Typed-Dataset which has our database schema in...
1
2984
by: Steven Thomas | last post by:
Can some one help me find a code snipit for saving the contents of a data set to a comma seperated file? I have created a web service in asp.net that will read the data from a AS/400 DB2...
7
5221
by: Sick | last post by:
My application populates a ListBox from a .TXT file. In the textfile there are prices with both dots as well as comma's for decimal indication. Example: 1234990; xg-tr-45; 1700,50; 0 2662666;...
4
12763
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
1
2456
by: CJK | last post by:
this is what i have so far: #include <iostream> #include <string> #include <vector> #include <fstream> using namespace std; class Person {
0
1203
by: Hoop | last post by:
Hi, I have a VB app that I am trying to open a text file where the data is comma seperated. I would like to save that file so that the user can open it in Excel rows and columns. I have code...
0
1834
by: Kristi | last post by:
I need to create a CL program that will take a PF, and create a tab delimited file that has comma seperated column headings as the first record. I know i can use cpytostmf/cpytoimpf to create the...
3
993
by: =?Utf-8?B?a2FyaW0=?= | last post by:
Hello All, I have a simple app, 1 button and 3 text boxes. the button is a save button. when I save to a file, it save every thing to a (.txt) file. now if I want to save to an excel sheet, I just...
0
7051
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
6915
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
7054
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7097
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...
1
6750
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5353
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
4493
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3003
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.