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 July 25th, 2003, 02:14 PM
Authorized User
 
Join Date: Jul 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ALoPresto
Default ASP SQL fields in order

I have a command string that I execute to call specific fields from a table. I want to then output the rows in a table. However, the fields will change, and rather than constantly change the output table, I made a function (similar to the one in the Wrox book) to output the table dynamically. As many know, the "For each field in objRS.Fields" outputs the fields in reverse order from the order they were in the command string. I have code that should prevent that, but somewhere I'm making an error. Thanks to anyone who can help fix this

Code:
<%
...Set up SQL
    strCommandText = "select name, telephoneNumber, mail, streetAddress, l, st, postalCode, title, department, manager, mobile from 'LDAP://tt1000' where objectClass='user' and objectCategory='person'"
...Execute the command & store to objRS
        RecToTable(objRS)
%>

<%
Function RecToTable (objRS)
    Dim strT
    Dim fldF
    strT = "<table border=1><tr align=center>"

'Out of order
'    For each fldF in objRS.fields
'        strT = strT & "<td>" & fldF.Name & "</td>"
'    Next
'    strT = strT & "</tr>"

'    While Not objRS.EOF
'        strT = strT & "<tr align=center>"
'        for each fldF in objRS.fields
'            strT = strT & "<td>" & fldF.value & "</td>"
'        Next
'        strT = strT & "</tr>"
'        objRS.Movenext
'    Wend
'    strT = strT & "</table>"
'    RecToTable = strT

'----------------In order
    For int i = 0 to objRS.Fields.Count - 1
        strT = strT & "<td>" & objRS.Fields(i).Name & "</td>"
    Next
    strT = strT & "</tr>"

    While Not objRS.EOF
        strT = strT & "<tr align=center>"
        for int i = 0 to objRS.Fields.Count - 1
            strT = strT & "<td>" & objRS.Fields(i).value & "</td>"
        Next
        strT = strT & "</tr>"
        objRS.Movenext
    Wend
    strT = strT & "</table>"
    RecToTable = strT

end function
%>
__________________
Andy
AIM: LoPrestoAtWork

Trusant Technologies, LLC
 
Old July 25th, 2003, 02:45 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

What error do you get? What exactly is going wrong?

One thing I can see is the Int i construct:

Code:
For int i = 0 to objRS.Fields.Count - 1
    strT = strT & "<td>" & objRS.Fields(i).Name & "</td>"
Next
strT = strT & "</tr>"
You can't declare and use a variable like this in VBScript ASP.

Try this:

Code:
Dim i
For i = 0 to objRS.Fields.Count - 1
    strT = strT & "<td>" & objRS.Fields(i).Name & "</td>"
Next
strT = strT & "</tr>"
If this doesn't solve the problem, please provide a bit more detailed information about the errors you're getting.

HtH

Imar





---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old July 25th, 2003, 02:54 PM
Authorized User
 
Join Date: Jul 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ALoPresto
Default

Sorry, I fixed the problem. You were right about the int i, i also do C++ and get confused sometimes. Here is the final code

Code:
    For i = objRS.Fields.Count - 1 to 0 step -1
        strT = strT & "<td>" & objRS.Fields(i).Name & "</td>"
    Next
    strT = strT & "</tr>"

    While Not objRS.EOF
        strT = strT & "<tr align=center>"
        for i = objRS.Fields.Count - 1 to 0 step -1
            strT = strT & "<td>" & objRS.Fields(i).Value & "</td>"
        Next
        strT = strT & "</tr>"
        objRS.Movenext
    Wend
    strT = strT & "</table>"
    RecToTable = strT





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using ORDER BY in SQL on date field in ASP page saifi4u Classic ASP Professional 3 March 1st, 2008 07:40 PM
Using ORDER BY in SQL query in ASP page saifi4u Classic ASP Databases 1 February 29th, 2008 09:19 AM
Getting fields, specific order from xml using xslt Jaipal XSLT 4 July 23rd, 2007 11:35 AM
SQL "Order By" problem bear88 SQL Language 3 April 13th, 2005 10:45 AM
SQL "Order By" problem bear88 SQL Language 1 April 12th, 2005 12:18 AM





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