changing rs.field to records

Discussion in 'C#' started by gilgalbiblewheel, Jun 20, 2007.

  1. #1
    I have:
    <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>
    Code (markup):
    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.
     
    gilgalbiblewheel, Jun 20, 2007 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    do a GetRows()

    Dim RowData
    RowData = rs.GetRows()
    rs.close
    conn.close
    conn = nothing

    now you have RowData which is a 2 dimensional array of your records
     
    ccoonen, Jun 20, 2007 IP
  3. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Do I have to put the numbers within the brackets?
    rs.GetRows(2,0)

    Does this replace the rs.Fields?
     
    gilgalbiblewheel, Jun 20, 2007 IP
  4. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #4
    gilgalbiblewheel, Jun 21, 2007 IP
  5. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    hmmm i don't think that's what I'm looking for.
    I have:
    <%
    		DSNName = "DRIVER=Microsoft Access Driver (*.mdb);DBQ="
    		DSNName = DSNName & Server.MapPath("../../kjv.mdb")
    		DSNName = DSNName & ";PWD=" & "mypass"
    		
    		
    		'Opening Database connection
    		Set Conn = Server.CreateObject("ADODB.Connection")
    		Conn.Open DSNName
    		
    		set RS = Server.CreateObject("ADODB.recordset")
    		
    		'This SQL statement creates a list of spokes
    		SQL1 = "Select * from inssp"   [B][COLOR="Red"] 'url extensions table[/COLOR][/B]
    		
    		rs.Open sql1,conn, 1
    		%>
    		<%
    		i = 0
    		for each x in rs.Fields
    			if i = 0 then
    				i = 1
    			else
    				response.write("<span id='" & x.name &"'>" & x.name & "</span>")
    				' process the rest of the loop except the one ignored above
    			end if
    		next%>
    				<div id="divform">
    					<form name="frm" id="frm">
    						<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, "&")
    				'[B][COLOR="Red"]opening the bible table used to simply fetch the name of the book[/COLOR][/B]
    				'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) '[B][COLOR="Red"]for your info after splitting the url extension a(0) is "book=number" and a(1) is "chapter=number".  [/COLOR][/B]
    				rs2.Open sql2,conn2, 1 
    				response.Write(rs2("book_title") & " " & rs2("chapter")  ) ' [B][COLOR="Red"]book_title is the name of the book like genesis, exodus and chapter is the chapter[/COLOR][/B]	
    				'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
    		conn = nothing
    		%>
    Code (markup):
    except that the rs.Fields is not helpful in this (otherwise everything else runs smoothly). I need a populating by columns.
     
    gilgalbiblewheel, Jun 21, 2007 IP
  6. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #6
    Ok let's use a simple example from w3schools.com and work on that:
    <%
    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
    
    'The first number indicates how many records to copy
    'The second number indicates what recordnumber to start on
    p=rs.GetRows(8,0)
    rs.close
    conn.close
    
    
    'This example returns the value of the first
    'column in the first two records
    response.write(p(1,0))
    response.write("<br />")
    response.write(p(1,1))
    response.write("<br />")
    response.write(p(1,2))
    response.write("<br />")
    response.write(p(1,3))
    response.write("<br />")
    response.write(p(1,4))
    response.write("<br />")
    response.write(p(1,5))
    response.write("<br />")
    response.write(p(1,6))
    response.write("<br />")
    response.write(p(1,7))
    response.write("<br />")
    
    %>
    Code (markup):
    How do you make this ubound? With a for loop?
     
    gilgalbiblewheel, Jun 21, 2007 IP
  7. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #7
    so, now p has the 2-dim array.

    so you could do:

    for x = ubound(p,2)
    response.write p(0,x)
    response.write p(1,x)
    response.write p(2,x)
    next

    I believe its p(2,x) - if not try p(x,2) one or the other, hehe.
     
    ccoonen, Jun 22, 2007 IP