473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Exporting to CSV issue

I am using a SQL 2000 server and am trying to export results from a
query to a text file. The code is working, expect my CONTACTNAME field
has a comma, and my export is splitting that into 2 columns when I only
want it to be one.

Here is my code:
set conn = CreateObject("ADODB.Connection")
conn.open DSNtemp
set rs = conn.execute("select
contactname,contactnumber,contactnumber1,contactem ail,address,city,state
,zip,type,sqft,0,bedrooms,baths,lotsize,acreage,ga rage,comments,price,0,
0,CASE MAINPHOTO WHEN 0 THEN 0 ELSE 1 END [MAINPHOTO],county from
propertydata where active='Y'")
csvText = rs.getString(2,,",",VBCrLf)
rs.close: set rs = nothing
conn.close: set conn = nothing

set fso = CreateObject("Scripting.FileSystemObject")
set fs = fso.CreateTextFile(Server.MapPath("csv.csv"), true)
fs.writeline(csvText)
fs.close: set fs = nothing
set fso = nothing
Again, this works, but it splits CONTACTNAME into 2 columns. The same
probably in the DESCRIPTION field. How do get it to IGNORE the columns
in those fields?

Thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Aug 22 '05 #1
3 3648
Either don't allow commas in the data, or switch to a different delimiter.

Bob Lehmann

"Joey Martin" <jo**@infosmiths.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am using a SQL 2000 server and am trying to export results from a
query to a text file. The code is working, expect my CONTACTNAME field
has a comma, and my export is splitting that into 2 columns when I only
want it to be one.

Here is my code:
set conn = CreateObject("ADODB.Connection")
conn.open DSNtemp
set rs = conn.execute("select
contactname,contactnumber,contactnumber1,contactem ail,address,city,state
,zip,type,sqft,0,bedrooms,baths,lotsize,acreage,ga rage,comments,price,0,
0,CASE MAINPHOTO WHEN 0 THEN 0 ELSE 1 END [MAINPHOTO],county from
propertydata where active='Y'")
csvText = rs.getString(2,,",",VBCrLf)
rs.close: set rs = nothing
conn.close: set conn = nothing

set fso = CreateObject("Scripting.FileSystemObject")
set fs = fso.CreateTextFile(Server.MapPath("csv.csv"), true)
fs.writeline(csvText)
fs.close: set fs = nothing
set fso = nothing
Again, this works, but it splits CONTACTNAME into 2 columns. The same
probably in the DESCRIPTION field. How do get it to IGNORE the columns
in those fields?

Thanks!

*** Sent via Developersdex http://www.developersdex.com ***

Aug 22 '05 #2
GetString() saves some lines of code but is not as flexible for example
if you want to add some extra characters in certain places. And here
are some related links:

http://www.aspmessageboard.com/forum...?M=353414&F=31
&P=1

http://www.codingforums.com/showthre...2430post212430

http://www.asp101.com/puzzles/puzzle5_s7.asp

http://www.asp101.com/puzzles/puzzle5_s1.asp

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...

<<

I am using a SQL 2000 server and am trying to export results from a
query to a text file. The code is working, expect my CONTACTNAME field
has a comma, and my export is splitting that into 2 columns when I only
want it to be one.

Here is my code:
set conn = CreateObject("ADODB.Connection")
conn.open DSNtemp
set rs = conn.execute("select
contactname,contactnumber,contactnumber1,contactem ail,address,city,state
,zip,type,sqft,0,bedrooms,baths,lotsize,acreage,ga rage,comments,price,0,
0,CASE MAINPHOTO WHEN 0 THEN 0 ELSE 1 END [MAINPHOTO],county from
propertydata where active='Y'")
csvText = rs.getString(2,,",",VBCrLf)
rs.close: set rs = nothing
conn.close: set conn = nothing

set fso = CreateObject("Scripting.FileSystemObject")
set fs = fso.CreateTextFile(Server.MapPath("csv.csv"), true)
fs.writeline(csvText)
fs.close: set fs = nothing
set fso = nothing
Again, this works, but it splits CONTACTNAME into 2 columns. The same
probably in the DESCRIPTION field. How do get it to IGNORE the columns
in those fields?


*** Sent via Developersdex http://www.developersdex.com ***
Aug 22 '05 #3
The issue you are having is with the CSV format instead of the ASP
code. If a column value has a comma in it, you will need to place the
entire column value in quotes. Pretty simply VBScript will do it.

As said above, you will need to recode to loop through the records,
writing each column to the file. If there is a column value that
contains a ",", you will need to surround that whole value with quotes.

Mike Biang
Systems Developer
Cramer Development
ASP/ASP.NET/PHP

Aug 22 '05 #4

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

Similar topics

4
by: Dom Hicklin | last post by:
I have created a form onto which images can be dropped and thus added to the OLE field of a Table (Access 2000 linked to SQL 2000 server). I use the Stephen Lebans ExportOLE function to do this...
3
by: premmehrotra | last post by:
I am using Access 2000 and Oracle 9.2.0.x on a Windows 2000. I have setup Oracle 9.2 ODBC Driver (I have not yet figured how to set Microsoft's Oracle ODBC driver). I am exporting a table from...
8
by: chippy | last post by:
Hi, I've a VB script that creates a Access object in a word doc. Here is the full script. It works for all but the Export. Which always fails with a 3011 error. If I do the same in Access as a...
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
6
by: Kevin Humphreys | last post by:
Hi There, I am trying to export a recordset to an excel file using the Content Type below in the header. Response.ContentType = "application/vnd.ms-excel" Which works fine however the...
3
by: David P. Donahue | last post by:
I'm re-writing an application in C# that was originally written in Delphi 7. The heart of the application is a DataSet displayed in a DataGrid. One of the main functions of the previous...
5
by: =?Utf-8?B?c2NobWlkdGU=?= | last post by:
Hi How can I Export an HTML Table to excel? My goal is a button, and when the user clicks this button a popup appears asking the user to 'open' or 'save' the generated Excel file. Actually...
7
by: leninv | last post by:
Hi, I have the following code where 'recs' is a record set. For i=0 to recs.Fields.Count - 1 if i = 0 then pindnt = string(itmlvl*2," ") response.write pindnt &...
4
by: myemail.an | last post by:
Hi all, I use Access 2007 and have the following problems: when exporting banal select queries (either to Excel or to a csv file) I find that exporting often doesn't work and creates a file with...
0
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm exporting a COM interface from my C# application. I want to to export a function that will have an array argument of structs. The struct is like: public struct MyStaruct { int A; int...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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...

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.