Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 17th, 2004, 11:27 AM
Authorized User
 
Join Date: Jun 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default create string from For Each loop

I need to pull a bunch of name/value pairs from a recordset and write them to a flat file. I have everything working so far except I don't know how to turn the For Each loop into a string variable that I can write to the flat file. Below is the code I have that will write the information in the correct format to an asp page. Please help me turn it into a string.

For Each ofield in oRSNB.fields
  strField = ofield.name
  strValue = oRSNB.(strField)
  Response.Write strField & "=" & strValue & "|"
Next
 
Old March 17th, 2004, 12:27 PM
Authorized User
 
Join Date: Mar 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aliasp Send a message via Yahoo to aliasp
Default

hi there,
to do that you must in first write sql enqiery that can read all the recordset :

set ors = server.createobject("adodb.recordset")
Ssql = "SELECT * FROM XXXX "
ors.open Ssql,Application ("conn1"),adopenstatic,adcmdtable

and then make this loop to output all recrdset :

while not ors.eof
  .
  .
  .
 ors.movenext
wend

Reg



ali
 
Old March 17th, 2004, 12:43 PM
Authorized User
 
Join Date: Jun 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks much
Dale
 
Old March 17th, 2004, 01:18 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Once you have your SQL query returning the two columns you want, there is a really easy way to create a string out of the whole set of data with a single call to the recordset:

<recordset>.GetString(, , "=", "|", "")

The arguments are:
StringFormat (you can leave that empty)
NumRows (again, leave empty or -1 for all rows)
ColumnDelimiter
RowDelimeter
NullExpr (value to use for Null values, usually "")

The recordset handles all the looping of its data and will give you a completed string with all the data in the format you want.

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to loop a command for a string length? LordJaffa Excel VBA 5 June 5th, 2007 10:20 PM
create one string from various records paul20091968 Access VBA 1 January 4th, 2007 04:18 PM
create array for loop in FSO jfergy Classic ASP Professional 4 April 14th, 2006 09:59 PM
Output loop data to a string iloveoatmeal Classic ASP Basics 2 December 22nd, 2005 08:28 PM
Create an image table using a loop nvillare Classic ASP Basics 1 February 4th, 2004 02:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.