Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 20th, 2007, 09:31 PM
Friend of Wrox
Points: 1,107, Level: 13
Points: 1,107, Level: 13 Points: 1,107, Level: 13 Points: 1,107, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default changing rs.field to records

I have:
Code:
<select id="sel1" name="sel1" onchange="" size="20">
        <%do until rs.EOF%>

        <%            
        i = 0
        for each x in rs.Fields
            if i = 0 then
                i = 1
            else
        %>
                <option href="showverse.asp?<%Response.Write(x.value)%>">
            <%
            'OPTION EXPLICIT
            dim txt,a
            If IsNull(x.value) then
                response.write("")
            else
                txt= x.value
                a=Split(txt, "&")
                'opening the bible table
                'Opening Database connection
                Set Conn2 = Server.CreateObject("ADODB.Connection")
                Conn2.Open DSNName

                set RS2 = Server.CreateObject("ADODB.recordset")

                'This SQL statement creates a list of books
                SQL2 = "Select * from bible"

                sql2 = sql2 & " where " & a(0) & " AND " & a(1)
                rs2.Open sql2,conn2, 1 
                response.Write(rs2("book_title") & " " & rs2("chapter") )    
                'response.Write(sql2)

                rs2.close
                conn2.close
                'response.write(a(0) & " ")
                'response.write(a(1))
            end if    
            %>
                </option>
        <%                      
        ' process the rest of the loop except the one ignored above
        end if
        next
        rs.MoveNext%>

        <%loop
        rs.close
        conn.close%>
                        </select>


At first I had a table where rs.Fields was suitable but I want to change to select dropdowns. I'm trying to think how I'm going to be able to make the script populate the 22 dropdowns (according to the 22 fields) instead of populating record-by-record.

Reply With Quote
  #2 (permalink)  
Old June 22nd, 2007, 10:40 PM
Friend of Wrox
Points: 1,107, Level: 13
Points: 1,107, Level: 13 Points: 1,107, Level: 13 Points: 1,107, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

For some reason the code is making an extra select field than the number of fields available in the database table and it's giving an error:

Quote:
quote:<span class='spokes' id='spoke23'>Spoke 23<br />
<select class='selspokes' id='sp23'>

<p>Microsoft VBScript runtime error '800a0009'
<p>
Subscript out of range: '23'
<p>
/wheelofgod/search/cat/biblewheeldata1.asp, line 119
Code:
                        <%
                        set conn=Server.CreateObject("ADODB.Connection")
                        conn.Provider="Microsoft.Jet.OLEDB.4.0"
                        conn.Open(Server.Mappath("../../kjv.mdb"))
                        set rs = Server.CreateObject("ADODB.recordset")
                        rs.Open "Select * from inssp", conn
                            arrayR = rs.GetRows()                'This has been altered to use an ARRAY. Because we are not putting limits on it (i.e. (8,0), we have made it dynamic AND 2-dimensional
                            maxC = rs.Fields.Count                'This line creates variable maxC, sets it to max fields in database
                            maxR = UBOUND(arrayR,2)                'This line creates variable called maxP, defines it as the upper limit of our array.
                        rs.close
                        conn.close

                        For y=1 to maxR                        'Loop through the ARRAY ROWS starting at 0 to the upper limit of our array
                            Response.write("<span class='spokes' id='spoke" & y & "'>Spoke " & y & "<br />")
                            Response.write("<select class='selspokes' id='sp" & y & "'>")
                            For x=0 to maxC                'Loop through the ARRAY COLUMNS starting at 0 to MAX COLUMNs minus 1 (since we are starting at 0)


                                    'OPTION EXPLICIT
                                    dim txt,a
                                    If IsNull(arrayR(y,x)) then
                                        response.write("")
                                    else
                                        response.write("<option href='showverse.asp?" & arrayR(y,x) & "'>")                                    
                                        txt= arrayR(y,x) 'x.value
                                        a=Split(txt, "&")
                                        'response.write(a(0) & " ")
                                        'response.write(a(1))

                                        'opening the bible table
                                        'Opening Database connection
                                        set conn2=Server.CreateObject("ADODB.Connection")
                                        conn2.Provider="Microsoft.Jet.OLEDB.4.0"
                                        conn2.Open(Server.Mappath("../../kjv.mdb"))
                                        set rs2 = Server.CreateObject("ADODB.recordset")


                                        'This SQL statement creates a list of books
                                        SQL2 = "Select * from bible"

                                        sql2 = sql2 & " where " & a(0) & " AND " & a(1)
                                        rs2.Open sql2,conn2, 1 
                                        response.Write(rs2("book_title") & " " & rs2("chapter") )    
                                        'response.Write(sql2)

                                        rs2.close
                                        conn2.close
                                        response.Write("</option>")    'Here, instead of p(1,0), we want to use the ARRAY. Also, we are combining the 2 response.write lines together
                                    end if    



                            Next
                            Response.write("</select></span><br />")
                        Next

                        '
                        response.flush                        'Flush Response buffer to screen
                        '
                        Erase arrayR
                        Set rs = nothing
                        Set conn = nothing
                        %>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning ASP 3.0: changing text field to checkbox AlanM Classic ASP Basics 0 July 1st, 2007 03:36 AM
Changing table field types in VB scubasteve Access VBA 1 June 12th, 2006 12:24 PM
MS RS Changing Server port Number jcredk BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 September 2nd, 2004 03:48 AM
RS Manager and RS Server on 2 different computers Choose File BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 July 22nd, 2004 10:56 AM
Changing ADO Recordset Field Type Niaz Pro VB Databases 0 January 18th, 2004 02:54 AM



All times are GMT -4. The time now is 05:08 PM.


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