Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Finding the number of columns in a recordset


Message #1 by "Azinger, Richard" <richard.azinger@p...> on Wed, 22 Jan 2003 10:12:52 -0600
Hello List,

I'm trying to write a function that when given a recordset will output the
names and values to all of the information in that recordset. Below is the
start of the code but the part I don't know about is how to find the length
(# of columns)/recordset. 

Thanks in advance for any help,

Rich Azinger


==============================================================

	rstSessionList3.moveFirst
	tempString = ""
	do while NOT rstSessionList3.EOF
		for x = 0 to rstSessionList3.length
			tempString = tempString & rstSessionList3(x).name
&": "&rstSessionList3(x)& threeSp
			rstSessionList3.moveNext
		next
		tempString = tempString &"<br>"
	loop
	response.Write("tempString = <br>"&tempString&"<br>")


This communication is for use by the intended recipient and contains 
information that may be privileged, confidential or copyrighted under
applicable law.  If you are not the intended recipient, you are hereby
formally notified that any use, copying or distribution of this e-mail,
in whole or in part, is strictly prohibited.  Please notify the sender
by return e-mail and delete this e-mail from your system.  Unless
explicitly and conspicuously designated as "E-Contract Intended",
this e-mail does not constitute a contract offer, a contract amendment,
or an acceptance of a contract offer.  This e-mail does not constitute
a consent to the use of sender's contact information for direct marketing
purposes or for transfers of data to third parties.

 Francais Deutsch Italiano  Espanol  Portugues  Japanese  Chinese  Korean

            http://www.DuPont.com/corp/email_disclaimer.html


Message #2 by "Peter Foti (PeterF)" <PeterF@S...> on Wed, 22 Jan 2003 11:59:39 -0500
This code will write out the field names, followed by the contents of the
recordset, but it doesn't give you the # of columns.  Assumes your recordset
is oRS.  Also, this prints &nbsp; for empty fields... not sure if the
conditional check (If Not oRS(Item.Name) = "" Then) will cause a problem
with non-text fields.


If Not oRS.EOF Then
	Response.Write("<table>")
	
	' Write the column names
	For Each Item In oRS.Fields
		Response.Write("<th>" & Item.Name & "</th>")
	Next

	' Write the records
	Do While Not oRS.EOF
		Response.write("<tr>")
		For Each Item In oRS.Fields
			If Not oRS(Item.Name) = "" Then
				Response.write("<td>" & oRS(Item.Name) &
"</td>")
			Else
				Response.write("<td>&nbsp;</td>")
			End If
		Next
		Response.write("</tr>")
		oRS.MoveNext
	Loop
	
	Response.Write("</table>")
End If

Hope this helps.
Peter Foti



> -----Original Message-----
> From: Azinger, Richard [mailto:richard.azinger@p...]
> Sent: Wednesday, January 22, 2003 11:13 AM
> To: ASP Databases
> Subject: [asp_databases] Finding the number of columns in a recordset
> 
> 
> 
> Hello List,
> 
> I'm trying to write a function that when given a recordset 
> will output the
> names and values to all of the information in that recordset. 
> Below is the
> start of the code but the part I don't know about is how to 
> find the length
> (# of columns)/recordset. 
> 
> Thanks in advance for any help,
> 
> Rich Azinger
> 
> 
> ==============================================================
> 
> 	rstSessionList3.moveFirst
> 	tempString = ""
> 	do while NOT rstSessionList3.EOF
> 		for x = 0 to rstSessionList3.length
> 			tempString = tempString & 
> rstSessionList3(x).name
> &": "&rstSessionList3(x)& threeSp
> 			rstSessionList3.moveNext
> 		next
> 		tempString = tempString &"<br>"
> 	loop
> 	response.Write("tempString = <br>"&tempString&"<br>")
> 
> 
> This communication is for use by the intended recipient and contains 
> information that may be privileged, confidential or copyrighted under
> applicable law.  If you are not the intended recipient, you are hereby
> formally notified that any use, copying or distribution of 
> this e-mail,
> in whole or in part, is strictly prohibited.  Please notify the sender
> by return e-mail and delete this e-mail from your system.  Unless
> explicitly and conspicuously designated as "E-Contract Intended",
> this e-mail does not constitute a contract offer, a contract 
> amendment,
> or an acceptance of a contract offer.  This e-mail does not constitute
> a consent to the use of sender's contact information for 
> direct marketing
> purposes or for transfers of data to third parties.
> 
>  Francais Deutsch Italiano  Espanol  Portugues  Japanese  
> Chinese  Korean
> 
>             http://www.DuPont.com/corp/email_disclaimer.html
> 
> 
> 
> 
Message #3 by Colin.Montgomery@C... on Wed, 22 Jan 2003 17:03:09 -0000
can't you just do:

rs.Fields.Count      ?

or if not, a loop something like:

for each fld in rs.Fields
	intFields = intFields + 1
next fld

?

HTH,
Col

-----Original Message-----
From: Peter Foti (PeterF) [mailto:PeterF@S...]
Sent: 22 January 2003 17:00
To: ASP Databases
Subject: [asp_databases] RE: Finding the number of columns in a
recordset


This code will write out the field names, followed by the contents of the
recordset, but it doesn't give you the # of columns.  Assumes your recordset
is oRS.  Also, this prints &nbsp; for empty fields... not sure if the
conditional check (If Not oRS(Item.Name) = "" Then) will cause a problem
with non-text fields.


If Not oRS.EOF Then
	Response.Write("<table>")
	
	' Write the column names
	For Each Item In oRS.Fields
		Response.Write("<th>" & Item.Name & "</th>")
	Next

	' Write the records
	Do While Not oRS.EOF
		Response.write("<tr>")
		For Each Item In oRS.Fields
			If Not oRS(Item.Name) = "" Then
				Response.write("<td>" & oRS(Item.Name) &
"</td>")
			Else
				Response.write("<td>&nbsp;</td>")
			End If
		Next
		Response.write("</tr>")
		oRS.MoveNext
	Loop
	
	Response.Write("</table>")
End If

Hope this helps.
Peter Foti



> -----Original Message-----
> From: Azinger, Richard [mailto:richard.azinger@p...]
> Sent: Wednesday, January 22, 2003 11:13 AM
> To: ASP Databases
> Subject: [asp_databases] Finding the number of columns in a recordset
> 
> 
> 
> Hello List,
> 
> I'm trying to write a function that when given a recordset 
> will output the
> names and values to all of the information in that recordset. 
> Below is the
> start of the code but the part I don't know about is how to 
> find the length
> (# of columns)/recordset. 
> 
> Thanks in advance for any help,
> 
> Rich Azinger
> 
> 
> ==============================================================
> 
> 	rstSessionList3.moveFirst
> 	tempString = ""
> 	do while NOT rstSessionList3.EOF
> 		for x = 0 to rstSessionList3.length
> 			tempString = tempString & 
> rstSessionList3(x).name
> &": "&rstSessionList3(x)& threeSp
> 			rstSessionList3.moveNext
> 		next
> 		tempString = tempString &"<br>"
> 	loop
> 	response.Write("tempString = <br>"&tempString&"<br>")
> 
> 
> This communication is for use by the intended recipient and contains 
> information that may be privileged, confidential or copyrighted under
> applicable law.  If you are not the intended recipient, you are hereby
> formally notified that any use, copying or distribution of 
> this e-mail,
> in whole or in part, is strictly prohibited.  Please notify the sender
> by return e-mail and delete this e-mail from your system.  Unless
> explicitly and conspicuously designated as "E-Contract Intended",
> this e-mail does not constitute a contract offer, a contract 
> amendment,
> or an acceptance of a contract offer.  This e-mail does not constitute
> a consent to the use of sender's contact information for 
> direct marketing
> purposes or for transfers of data to third parties.
> 
>  Francais Deutsch Italiano  Espanol  Portugues  Japanese  
> Chinese  Korean
> 
>             http://www.DuPont.com/corp/email_disclaimer.html
> 
> 
> 
> 



*******

This message and any attachment are confidential and may be privileged or otherwise protected from disclosure.  If you are not the
intended recipient, please telephone or email the sender and delete this message and any attachment from your system.  If you are
not the intended recipient you must not copy this message or attachment or disclose the contents to any other person.

For further information about Clifford Chance please see our website at http://www.cliffordchance.com or refer to any Clifford
Chance office.


  Return to Index