473,765 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code Snipit for saving to CSV

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(B yVal varbpno, ByVal
varAcctperdid) As DataSet
Dim RecLocName As String
Dim AuthNO As String
Dim TktRecDt As Date
Dim RcdVolQT As String
Dim RcdCullQT As String
Dim SpProd As String

REM -- get the data from the database
Dim sqlText As String = "select reclocnm, a.authno, tktrecdt,
rcdvolqt, rcdcullqt, sppdfmgd from "
sqlText = sqlText + " ticket a, tktdtl b, recloc c, spprod d ,
auth e where a.tktid = b.tktid and a.acctperdid = b.acctperdid"
sqlText = sqlText + " and a.reclocid = c.reclocid and
b.spprodid = d.spprodid and a.authno = e.authno"
sqlText = sqlText + " and e.splrbpno = 1 and a.acctperdid =
222"
'sqlText = sqlText + " and e.splrbpno = " + varbpno + " and
a.acctperdid = " + varAcctperdid
Dim dbRead As OleDb.OleDbData Reader = GetDataReader(s qlText)

REM -- create the datatable
Dim ds As DataSet = New DataSet("Ticket Info")
Dim dt As DataTable = ds.Tables.Add(" TicketData")
Dim dr As DataRow

REM -- create the columns in the datatable
dt.Columns.Add( New DataColumn("Rec LocName",
System.Type.Get Type("System.St ring")))
dt.Columns.Add( New DataColumn("Aut hNO",
System.Type.Get Type("System.St ring")))
dt.Columns.Add( New DataColumn("Tkt RecDt",
System.Type.Get Type("System.St ring")))
dt.Columns.Add( New DataColumn("Rcd VolQT",
System.Type.Get Type("System.St ring")))
dt.Columns.Add( New DataColumn("Rcd CullQT",
System.Type.Get Type("System.St ring")))
dt.Columns.Add( New DataColumn("SpP rod",
System.Type.Get Type("System.St ring")))

While dbRead.Read()
RecLocName = dbRead.Item("Re cLocNM").ToStri ng()
AuthNO = dbRead.Item("Au thNO").ToString ()
TktRecDt =
DateTime.Parse( dbRead.Item("Tk tRecDT").ToStri ng())
RcdVolQT = dbRead.Item("Rc dVolQT").ToStri ng()
RcdCullQT = dbRead.Item("Rc dCullQT").ToStr ing()
SpProd = dbRead.Item("SP PDFMGD").ToStri ng()

REM -- Add to DataSet ds
dr = dt.NewRow()
dt.Rows.Add(dr)
End While

'Return ds


End Function
-------------------------------------------------------------
Thanks for any help.
Nov 17 '05 #1
1 3000
Here's some code that might give you some ideas...
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
'Set the appropriate ContentType.
Dim filename As String = "orderdetails.c sv"
Dim myCommand As New SqlCommand _
("select * from [order details] ", SqlConnection1)
myCommand.Conne ction.Open()
Dim myReader As SqlDataReader = _
myCommand.Execu teReader(Comman dBehavior.Close Connection)
Dim i As Integer
Dim sb As New System.Text.Str ingBuilder
For i = 0 To myReader.FieldC ount - 1
If i < (myReader.Field Count - 1) Then
sb.Append(Chr(3 4) & myReader.GetNam e(i) & Chr(34) & ",")
Else
sb.Append(Chr(3 4) & myReader.GetNam e(i) & Chr(34) & vbCrLf)
End If
Next

While myReader.Read()
For i = 0 To myReader.FieldC ount - 1
If i < (myReader.Field Count - 1) Then
sb.Append(Chr(3 4) & myReader.GetVal ue(i).ToString & _
Chr(34) & ",")
Else
sb.Append(Chr(3 4) & myReader.GetVal ue(i).ToString & _
Chr(34) & vbCrLf)
End If
Next

End While

myReader.Close( )
SqlConnection1. Close()
Response.Conten tType = "Applicatio n/x-msexcel"
Response.AddHea der _
("content-disposition", "attachment ; filename=""" & filename & """")
'Write the file directly to the HTTP output stream.
Response.Write( sb.ToString)
Response.End()
End Sub

"Steven Thomas" <st******@gapac .com> wrote in message
news:61******** *************** ***@posting.goo gle.com...
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(B yVal varbpno, ByVal
varAcctperdid) As DataSet
Dim RecLocName As String
Dim AuthNO As String
Dim TktRecDt As Date
Dim RcdVolQT As String
Dim RcdCullQT As String
Dim SpProd As String

REM -- get the data from the database
Dim sqlText As String = "select reclocnm, a.authno, tktrecdt,
rcdvolqt, rcdcullqt, sppdfmgd from "
sqlText = sqlText + " ticket a, tktdtl b, recloc c, spprod d ,
auth e where a.tktid = b.tktid and a.acctperdid = b.acctperdid"
sqlText = sqlText + " and a.reclocid = c.reclocid and
b.spprodid = d.spprodid and a.authno = e.authno"
sqlText = sqlText + " and e.splrbpno = 1 and a.acctperdid =
222"
'sqlText = sqlText + " and e.splrbpno = " + varbpno + " and
a.acctperdid = " + varAcctperdid
Dim dbRead As OleDb.OleDbData Reader = GetDataReader(s qlText)

REM -- create the datatable
Dim ds As DataSet = New DataSet("Ticket Info")
Dim dt As DataTable = ds.Tables.Add(" TicketData")
Dim dr As DataRow

REM -- create the columns in the datatable
dt.Columns.Add( New DataColumn("Rec LocName",
System.Type.Get Type("System.St ring")))
dt.Columns.Add( New DataColumn("Aut hNO",
System.Type.Get Type("System.St ring")))
dt.Columns.Add( New DataColumn("Tkt RecDt",
System.Type.Get Type("System.St ring")))
dt.Columns.Add( New DataColumn("Rcd VolQT",
System.Type.Get Type("System.St ring")))
dt.Columns.Add( New DataColumn("Rcd CullQT",
System.Type.Get Type("System.St ring")))
dt.Columns.Add( New DataColumn("SpP rod",
System.Type.Get Type("System.St ring")))

While dbRead.Read()
RecLocName = dbRead.Item("Re cLocNM").ToStri ng()
AuthNO = dbRead.Item("Au thNO").ToString ()
TktRecDt =
DateTime.Parse( dbRead.Item("Tk tRecDT").ToStri ng())
RcdVolQT = dbRead.Item("Rc dVolQT").ToStri ng()
RcdCullQT = dbRead.Item("Rc dCullQT").ToStr ing()
SpProd = dbRead.Item("SP PDFMGD").ToStri ng()

REM -- Add to DataSet ds
dr = dt.NewRow()
dt.Rows.Add(dr)
End While

'Return ds


End Function
-------------------------------------------------------------
Thanks for any help.
Nov 17 '05 #2

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

Similar topics

1
1904
by: max | last post by:
I am trying to use a sdk to access quickbooks, the sdk provided a COM interface and I think it installed the com server files/dlls. A VB code example is provided, but I can't figure out how to map "Dim sessionManager As New QBFC2_1Lib.QBSessionManager" into a corresponding Python statement, when I try obj = win32com.Client.Dispatch("QBFC2_1Lib.QBSessionManager") I get traceback Shown below. I have been able to run makepy and it...
1
1919
by: Mahesh Devjibhai Dhola [MVP] | last post by:
Hi, User can adjust the size of columns of a table or the position of splitter in UI. We want these adjustments to be remembered when we restart the application. Currently, we are saving these adjustments by the user in an XML and saving that XML. We read the XML upon restart and make calls to set the adjustments. This approach becomes difficult as we add more controls and more settings can be made by the user. What other techniques can...
14
5538
by: Amitabh Deepak | last post by:
Is there any way to check whether daylight saving is enabled on a linux machine?
4
10819
by: John Kandell | last post by:
Hi, I posted this in the asp.net group, but didn't get a response. Maybe someone here can help me with this... --- Would someone be able to shed some light on what is the cost of saving a DataTable to session vs saving a custom object of the same data.
1
2690
by: Eric | last post by:
Using the 1.1 framework. We are using a newly created instance of a RichTextBox Class in our server code to manipulate RTF that is stored in the database. To clarify, we are not using or attempting to use this class in the aspx page that calls the code, nor is the 'using System.Windows.Forms' referenced in any of the aspx pages. The first client using this software has been experiencing an error that we cannot reproduce in-house. The...
1
955
by: G Stark | last post by:
Hi, Anyone done this before? I need a snippet of code that will download a datagrid to be saved as a CSV file. I snippet found one to do excel, but I need CSV. -- G. Stark MIS Electro Rent Corp.
6
8843
by: Robm | last post by:
Since googling this issue only brings up the April fool's problem, which was solved years ago, I hope that somebody can help me with this. I have a large vc++/mfc application which needs to know when DST is in effect. This has been working fine for years, but I am worried about the upcoming change in 2007 in the US, which will be followed by a number of Canadian provices (where my application is used). The function that I use is very...
0
2066
by: Cause | last post by:
In the following code to call my website for serial registration reasons, I want to test on localhost. The code works on the internet, but this code sends me a bunch of 400 bad request errors when I use appache on port 80 localhost. Here's the code: ////////////////////////////////////////////////////////////////////////////////////// /* * http_post.cpp *
27
6889
by: RobG | last post by:
I was investigating a function to determine whether daylight saving was being observed on a particular date (given the platform's regional settings) and came across a suggestion at merlyn.com to test the time zone offset on a variety of dates to see if it changes. Based on that, I developed the following checkDST() function which, as far as I can tell, should be sufficient. It checks either the date passed to it or the current date with...
0
9568
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
10007
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
9951
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
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
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
7375
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
6649
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
5275
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...
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.