473,796 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comma Delimited

Hi,

I am looking to create a report comma delimited on a click of a button.

Explanantion:
1. Get from the database: "SELECT * FROM Customers WHERE Region = 'CA'"
2. Use either DataReader or DataSource
3. Create a button "Export"
4. On ServerClick Event prompt user to save as a text comma delimited file.

Can someone help me?

Yama
Nov 20 '05 #1
5 2720
Yama,
Here's a quick VB.NET 1.1 export routine that is very general (too
general?):

Its based on a DataSet, however you should be able to adopt it to a
DataReader instead.

' Required imports
Imports System.IO ' for the StreamWriter
Imports System.Text ' for the UnicodeEncoding

' sample usage
Export("Custome rs.csv", DataSet1.Tables ("Customers" ))
Export("Employe es.csv", DataSet1.Tables ("Employees" ))
Public Sub Export(ByVal path As String, ByVal table As DataTable)
Dim output As New StreamWriter(pa th, False, UnicodeEncoding .Default)
Dim delim As String

' Write out the header row
delim = ""
For Each col As DataColumn In table.Columns
output.Write(de lim)
output.Write(co l.ColumnName)
delim = ","
Next
output.WriteLin e()

' write out each data row
For Each row As DataRow In table.Rows
delim = ""
For Each value As Object In row.ItemArray
output.Write(de lim)
If TypeOf value Is String Then
output.Write("" ""c) ' thats four double quotes and a c
output.Write(va lue)

output.Write("" ""c) ' thats four double quotes and a c
Else
output.Write(va lue)
End If
delim = ","
Next
output.WriteLin e()
Next

output.Close()

End Sub

You can change (or remove) the Encoding parameter above to suit your needs,
I used Unicode as the table had non ASCII characters in it. Also when
writing strings, I don't deal with double quotes in the string. If you make
the StreamWriter a parameter it will be much more flexible (you could go to
a memory stream to support cut & paste). I use the default formatting for
numeric types.

You can change it to use a DataView (for sorting & filtering for example) by
changing the following lines:

'Public Sub Export(ByVal path As String, ByVal table As DataTable)
Public Sub Export(ByVal path As String, ByVal view As DataView)

'For Each col As DataColumn In table.Columns
For Each col As DataColumn In view.Table.Colu mns

'For Each row As DataRow In table.Rows
For Each row As DataRowView In view

'For Each value As Object In row.ItemArray
For Each value As Object In row.Row.ItemArr ay
Hope this helps
Jay
"Yama" <yk*****@grandp acificresorts.c om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

I am looking to create a report comma delimited on a click of a button.

Explanantion:
1. Get from the database: "SELECT * FROM Customers WHERE Region = 'CA'"
2. Use either DataReader or DataSource
3. Create a button "Export"
4. On ServerClick Event prompt user to save as a text comma delimited file.
Can someone help me?

Yama

Nov 20 '05 #2
Wow!

You are da man!

Thanks to you I am sure many other people will refer to this thread... Well
maybe.

Thank you anyway. Your help was certainly appreciated by me.

Yama
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:OR******** ******@TK2MSFTN GP11.phx.gbl...
Yama,
Here's a quick VB.NET 1.1 export routine that is very general (too
general?):

Its based on a DataSet, however you should be able to adopt it to a
DataReader instead.

' Required imports
Imports System.IO ' for the StreamWriter
Imports System.Text ' for the UnicodeEncoding

' sample usage
Export("Custome rs.csv", DataSet1.Tables ("Customers" ))
Export("Employe es.csv", DataSet1.Tables ("Employees" ))
Public Sub Export(ByVal path As String, ByVal table As DataTable)
Dim output As New StreamWriter(pa th, False, UnicodeEncoding .Default) Dim delim As String

' Write out the header row
delim = ""
For Each col As DataColumn In table.Columns
output.Write(de lim)
output.Write(co l.ColumnName)
delim = ","
Next
output.WriteLin e()

' write out each data row
For Each row As DataRow In table.Rows
delim = ""
For Each value As Object In row.ItemArray
output.Write(de lim)
If TypeOf value Is String Then
output.Write("" ""c) ' thats four double quotes and a c
output.Write(va lue)

output.Write("" ""c) ' thats four double quotes and a c
Else
output.Write(va lue)
End If
delim = ","
Next
output.WriteLin e()
Next

output.Close()

End Sub

You can change (or remove) the Encoding parameter above to suit your needs, I used Unicode as the table had non ASCII characters in it. Also when
writing strings, I don't deal with double quotes in the string. If you make the StreamWriter a parameter it will be much more flexible (you could go to a memory stream to support cut & paste). I use the default formatting for
numeric types.

You can change it to use a DataView (for sorting & filtering for example) by changing the following lines:

'Public Sub Export(ByVal path As String, ByVal table As DataTable)
Public Sub Export(ByVal path As String, ByVal view As DataView)

'For Each col As DataColumn In table.Columns
For Each col As DataColumn In view.Table.Colu mns

'For Each row As DataRow In table.Rows
For Each row As DataRowView In view

'For Each value As Object In row.ItemArray
For Each value As Object In row.Row.ItemArr ay
Hope this helps
Jay
"Yama" <yk*****@grandp acificresorts.c om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

I am looking to create a report comma delimited on a click of a button.

Explanantion:
1. Get from the database: "SELECT * FROM Customers WHERE Region = 'CA'"
2. Use either DataReader or DataSource
3. Create a button "Export"
4. On ServerClick Event prompt user to save as a text comma delimited

file.

Can someone help me?

Yama


Nov 20 '05 #3
Hi,

I am using the following:
response.Clear( )

response.ClearC ontent()

'set the response mime type for text

response.Conten tType = "text/plain"

HttpContext.Cur rent.Applicatio nInstance.Compl eteRequest()

But instead of the user being prompted to save output as TEXT they are
prompted to save as ASPX. Although changing it to a .TXT will save the
content as a text file. How to force IE to display the dialog box to save as
TEXT?

Yama

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:OR******** ******@TK2MSFTN GP11.phx.gbl...
Yama,
Here's a quick VB.NET 1.1 export routine that is very general (too
general?):

Its based on a DataSet, however you should be able to adopt it to a
DataReader instead.

' Required imports
Imports System.IO ' for the StreamWriter
Imports System.Text ' for the UnicodeEncoding

' sample usage
Export("Custome rs.csv", DataSet1.Tables ("Customers" ))
Export("Employe es.csv", DataSet1.Tables ("Employees" ))
Public Sub Export(ByVal path As String, ByVal table As DataTable)
Dim output As New StreamWriter(pa th, False, UnicodeEncoding .Default) Dim delim As String

' Write out the header row
delim = ""
For Each col As DataColumn In table.Columns
output.Write(de lim)
output.Write(co l.ColumnName)
delim = ","
Next
output.WriteLin e()

' write out each data row
For Each row As DataRow In table.Rows
delim = ""
For Each value As Object In row.ItemArray
output.Write(de lim)
If TypeOf value Is String Then
output.Write("" ""c) ' thats four double quotes and a c
output.Write(va lue)

output.Write("" ""c) ' thats four double quotes and a c
Else
output.Write(va lue)
End If
delim = ","
Next
output.WriteLin e()
Next

output.Close()

End Sub

You can change (or remove) the Encoding parameter above to suit your needs, I used Unicode as the table had non ASCII characters in it. Also when
writing strings, I don't deal with double quotes in the string. If you make the StreamWriter a parameter it will be much more flexible (you could go to a memory stream to support cut & paste). I use the default formatting for
numeric types.

You can change it to use a DataView (for sorting & filtering for example) by changing the following lines:

'Public Sub Export(ByVal path As String, ByVal table As DataTable)
Public Sub Export(ByVal path As String, ByVal view As DataView)

'For Each col As DataColumn In table.Columns
For Each col As DataColumn In view.Table.Colu mns

'For Each row As DataRow In table.Rows
For Each row As DataRowView In view

'For Each value As Object In row.ItemArray
For Each value As Object In row.Row.ItemArr ay
Hope this helps
Jay
"Yama" <yk*****@grandp acificresorts.c om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

I am looking to create a report comma delimited on a click of a button.

Explanantion:
1. Get from the database: "SELECT * FROM Customers WHERE Region = 'CA'"
2. Use either DataReader or DataSource
3. Create a button "Export"
4. On ServerClick Event prompt user to save as a text comma delimited

file.

Can someone help me?

Yama


Nov 20 '05 #4
Yama,
I do little or no ASP.NET...

If no one here gives you an answer, you may want to ask this question "down
the hall" in the microsoft.publi c.dotnet.framew ork.aspnet newsgroup.

Hope this helps
Jay

"Yama" <yk*****@grandp acificresorts.c om> wrote in message
news:uW******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I am using the following:
response.Clear( )

response.ClearC ontent()

'set the response mime type for text

response.Conten tType = "text/plain"

HttpContext.Cur rent.Applicatio nInstance.Compl eteRequest()

But instead of the user being prompted to save output as TEXT they are
prompted to save as ASPX. Although changing it to a .TXT will save the
content as a text file. How to force IE to display the dialog box to save as TEXT?

Yama

Nov 20 '05 #5
Before using Response.Write( csvtext) use:

Page.Response.A ddHeader("conte nt-disposition",
"attachment;fil ename=output.cs v")

"Yama" <yk*****@grandp acificresorts.c om> wrote in message
news:uW******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I am using the following:
response.Clear( )

response.ClearC ontent()

'set the response mime type for text

response.Conten tType = "text/plain"

HttpContext.Cur rent.Applicatio nInstance.Compl eteRequest()

But instead of the user being prompted to save output as TEXT they are
prompted to save as ASPX. Although changing it to a .TXT will save the
content as a text file. How to force IE to display the dialog box to save as TEXT?

Yama

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:OR******** ******@TK2MSFTN GP11.phx.gbl...
Yama,
Here's a quick VB.NET 1.1 export routine that is very general (too
general?):

Its based on a DataSet, however you should be able to adopt it to a
DataReader instead.

' Required imports
Imports System.IO ' for the StreamWriter
Imports System.Text ' for the UnicodeEncoding

' sample usage
Export("Custome rs.csv", DataSet1.Tables ("Customers" ))
Export("Employe es.csv", DataSet1.Tables ("Employees" ))
Public Sub Export(ByVal path As String, ByVal table As DataTable)
Dim output As New StreamWriter(pa th, False, UnicodeEncoding .Default)
Dim delim As String

' Write out the header row
delim = ""
For Each col As DataColumn In table.Columns
output.Write(de lim)
output.Write(co l.ColumnName)
delim = ","
Next
output.WriteLin e()

' write out each data row
For Each row As DataRow In table.Rows
delim = ""
For Each value As Object In row.ItemArray
output.Write(de lim)
If TypeOf value Is String Then
output.Write("" ""c) ' thats four double quotes and a c output.Write(va lue)

output.Write("" ""c) ' thats four double quotes and a c Else
output.Write(va lue)
End If
delim = ","
Next
output.WriteLin e()
Next

output.Close()

End Sub

You can change (or remove) the Encoding parameter above to suit your

needs,
I used Unicode as the table had non ASCII characters in it. Also when
writing strings, I don't deal with double quotes in the string. If you

make
the StreamWriter a parameter it will be much more flexible (you could go

to
a memory stream to support cut & paste). I use the default formatting for numeric types.

You can change it to use a DataView (for sorting & filtering for

example) by
changing the following lines:

'Public Sub Export(ByVal path As String, ByVal table As DataTable)
Public Sub Export(ByVal path As String, ByVal view As DataView)

'For Each col As DataColumn In table.Columns
For Each col As DataColumn In view.Table.Colu mns

'For Each row As DataRow In table.Rows
For Each row As DataRowView In view

'For Each value As Object In row.ItemArray
For Each value As Object In row.Row.ItemArr ay
Hope this helps
Jay
"Yama" <yk*****@grandp acificresorts.c om> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

I am looking to create a report comma delimited on a click of a button.
Explanantion:
1. Get from the database: "SELECT * FROM Customers WHERE Region = 'CA'" 2. Use either DataReader or DataSource
3. Create a button "Export"
4. On ServerClick Event prompt user to save as a text comma delimited

file.

Can someone help me?

Yama



Nov 20 '05 #6

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

Similar topics

4
2825
by: Arne | last post by:
From: "Arne de Booij" <a_de_booij@hotmail.com> Subject: Comma delimited array into DB problems Date: 9. februar 2004 10:39 Hi, I have an asp page that takes input from a form on the previous page, puts that into an array and inserts the array into SQL server. Now here is the problem:
4
4873
by: Christine Forber | last post by:
I wonder if anyone knows of some javascript code to check a comma-delimited list of email addresses for basic formating. What I'm looking for is the javascript code to check a form field on form submission. If there is an entry in the field, does it match the following: text@text.text, text@text.text,text@text.text where each address is between commas and each address is in the format
3
5435
by: Elmo Watson | last post by:
I've been asked to develop a semi-automated type situation where we have a database table (sql server) and periodically, there will be a comma delimited file from which we need to import the data, replacing the old. I naurally know that we can use to kill the other data, but does anyone have any examples of importing a comma delimited file into SQL Server with ASP?
2
4694
by: A E | last post by:
Hi, I was wondering if there was a function that handles list elements of a comma delimited list? I need to be able to pass values as a comma delimited list, count the number of values, and process the value of each. Did not think it was very efficient to loop through the contents of the list finding delimiters. TIA Alex
2
2015
by: Larry Williams | last post by:
Is there an easy way to convert a string of data to XML format without having to create the xml one field at a time? Sorry I'm a newbie and my xml knowledge is limited. I have tried to search through the documentation in .net but nothing jumps out at me. Sample code would be great!
1
6694
by: John B. Lorenz | last post by:
I'm attempting to write an input routine that reads from a comma delimited file. I need to read in one record at a time, assign each field to a field array and then continue with my normal processing. I am having no luck at all finding different routines written in C to read delimited files of any kind. I have a few ideas of how I might go about this but I bet I'm re-inventing the wheel and there already exists some efficient code out...
9
4515
by: Wayne | last post by:
I have the following string: "smith", "Joe", "West Palm Beach, Fl." I need to split this string based on the commas, but as you see the city state contains a comma. String.split will spilt the city state. Is there a built in function that I'm missing that will do the split and recognize that the comma in city state is part of the item? --
9
3640
by: Bernie Yaeger | last post by:
Is there a way to convert or copy a .xml file to a comma delimited text file using vb .net? Thanks for any help. Bernie Yaeger
4
4811
by: JustSomeGuy | last post by:
Hi. I have a comma delimited text file that I want to parse. I was going to use fscanf from the C library but as my app is written in C++ I thought I'd use the std io stream library... My Text file looks like: First_Name, Last_Name, ID, Date/Of/Birth<newline> depending on the host the newline is either \n or \r\n
2
2135
by: Ron | last post by:
so if my textbox is named textbox1 and my listbox is named ltsdisplay, for the button that would make this all happen I would just need to: lstdisplay.items.textbox1(delimited.Split(",".ToCharArray())) is that right? or no? I try this and I get an error...
0
9685
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
9533
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9057
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
7555
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
6796
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
5447
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...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.