Generate random query with all fields from an entry
am 23.02.2005 18:43:02 von andrewdreib
I'm trying to create an ASP page that will
randomly query the database and show entire entires. I found some code
online that prints on entry from the table, but only one piece of information
from it, and I'm hoping someone here know what I need to change to make it
print the entire entry.
Here's what I have:
============================================================ =
<%
Option Explicit
Response.Buffer = True
%>
<%
' ADO Constant. Dont change this
Const adCmdText = &H0001
' Connection string and SQL statement
Dim query, connStr
query = "select ID from numbers"
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Inetpub\wwwroot\numbers.mdb"
' Opening database
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open query, connStr, 3, , adCmdText
' Generating random number from total number of records
Dim intRnd
Randomize Timer
intRnd = (Int(RND * rs.RecordCount))
' Now moving the cursor to random record number
rs.Move intRnd
' Showing the random statement
Response.Write "" & rs("statement") & ""
' Closing the database
rs.Close
Set rs = Nothing
%>
============================================================ =
The fields in my table are ID, and F1-F10. I'll try to figure this out
myself, but help is definately appreciated.
Re: Generate random query with all fields from an entry
am 03.03.2005 02:19:10 von Bullschmidt
<<
I'm trying to create an ASP page that will
randomly query the database and show entire entires. I found some code
online that prints on entry from the table, but only one piece of
information
from it, and I'm hoping someone here know what I need to change to make
it
print the entire entry.
Here's what I have:
============================================================ =
<%
Option Explicit
Response.Buffer = True
%>
<%
' ADO Constant. Dont change this
Const adCmdText = &H0001
' Connection string and SQL statement
Dim query, connStr
query = "select ID from numbers"
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Inetpub\wwwroot\numbers.mdb"
' Opening database
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open query, connStr, 3, , adCmdText
' Generating random number from total number of records
Dim intRnd
Randomize Timer
intRnd = (Int(RND * rs.RecordCount))
' Now moving the cursor to random record number
rs.Move intRnd
' Showing the random statement
Response.Write "" & rs("statement") & ""
' Closing the database
rs.Close
Set rs = Nothing
%>
============================================================ =
The fields in my table are ID, and F1-F10. I'll try to figure this out
myself, but help is definately appreciated.
>>
Perhaps change this:
query = "select ID from numbers"
To be this instead:
query = "select * from numbers"
And then for this:
Response.Write "" & rs("statement") & ""
You can then perhaps show all the fields you want:
Response.Write "Last Name: " & rs("LName") & "
"
Response.Write "First Name: " & rs("FName") & "
"
Response.Write "City: " & rs("City") & "
"
Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!