473,748 Members | 7,590 Online
Bytes | Software Development & Data Engineering Community
+ 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 1277
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.c sv")
For i As Integer = 0 To ds.Tables(0).Ro ws.Count - 1
Dim row As New System.Text.Str ingBuilder
row.Append("""" )
For y As Integer = 0 To ds.Tables(0).Co lumns.Count - 1
row.Append(ds.T ables(0).Rows(i )(y).tostring)
If y <> ds.Tables(0).Co lumns.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(ro w.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**********@p lanet.nl> wrote in message
news:OW******** *****@TK2MSFTNG P12.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.c sv")
For i As Integer = 0 To ds.Tables(0).Ro ws.Count - 1
Dim row As New System.Text.Str ingBuilder
row.Append("""" )
For y As Integer = 0 To ds.Tables(0).Co lumns.Count - 1
row.Append(ds.T ables(0).Rows(i )(y).tostring)
If y <> ds.Tables(0).Co lumns.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(ro w.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
2539
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
1235
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 it and then try to load the CSV file into that Typed-Dataset and automatically get all the errors and constarint violations. 1) Is it doable? 2) Because I need to check the foriegn keys as well,Can I loaded the data of those refferecing...
1
2999
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 database via a OleDB connection. Then I create the dataset, Now what do I do Here is the function now ------------------------------------------------ Public Function GetTicketData() As DataSet 'Public Function GetTicketData(ByVal varbpno, ByVal
7
5237
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; hj-54-56; 1565.00; 0 8228880; 30-56-tw; 3295.50; 0 0022339; hs-sa-73; 2975,75; 0 .... etc
4
12808
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 to read text file but could not get the data in correct format. All columns are not coming in dataset and rows are messing up. Suggestions please ???
1
2471
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
1223
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 that will open and save the file in Excel but in needs to be delimited. What I have is below. How can I get this into Excel format? Thanks for any help.
0
1872
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 file, but how do i get the headings to be comma seperated while the rest of the file is tab delimited? Any help would be wonderful. Thank you
3
1003
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 change it to (.xls). when I do that it saves every thing under A1, A2, A3,...etc. how can I get each box I have to go to a certain block in the excel sheet? like A1, B2, C3... Thanks for all your help...
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9325
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8244
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3315
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 we have to send another system

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.