Hello,
Can anyone help me with this script. I'm trying to create a webpage that displays one random record from a database everytime the asp webpage is freshed. I used frontpage to create the webpage, and some members from other forums have given me some script and queries to use. below is some of the script and query that i recently recieved, but I am not familiar with opening or creating database connections or recordsets and I keep getting errors. the original code that i was given was this:
<%
' Initialize ASP RND() function
Randomize()
intRandomNumber = Int (1000*Rnd)+1
' Return 3 random records
strSQL = "SELECT TOP 1 Key, quote, Rnd(" & -1 * (intRandomNumber) & "*Key)" & "FROM Results" & "ORDER BY 3"
Set objRS = objConn.Execute(strSQL)
%>
but it gives me an "Object required:" error. so i looked in some other forums to see how to open database connections and recordset, and i've tried different variation, but i get different errors each time. The code that i have now is listed below. Does any of it look close to being right? Please let me know if anyone has any suggestions or if you need any more info. Thanks!
Can anyone help me with this script. I'm trying to create a webpage that displays one random record from a database everytime the asp webpage is freshed. I used frontpage to create the webpage, and some members from other forums have given me some script and queries to use. below is some of the script and query that i recently recieved, but I am not familiar with opening or creating database connections or recordsets and I keep getting errors. the original code that i was given was this:
<%
' Initialize ASP RND() function
Randomize()
intRandomNumber = Int (1000*Rnd)+1
' Return 3 random records
strSQL = "SELECT TOP 1 Key, quote, Rnd(" & -1 * (intRandomNumber) & "*Key)" & "FROM Results" & "ORDER BY 3"
Set objRS = objConn.Execute(strSQL)
%>
but it gives me an "Object required:" error. so i looked in some other forums to see how to open database connections and recordset, and i've tried different variation, but i get different errors each time. The code that i have now is listed below. Does any of it look close to being right? Please let me know if anyone has any suggestions or if you need any more info. Thanks!
Code:
<%
Dim objConn
Dim objRS
objConn = Server.CreateObject("ADODB.Connection")
objconn.ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=/fpdb/quotes.mdb"
'Initialize ASP RND() function
Randomize()
intRandomNumber = Int(1000*Rnd)+1
'Return 3 random records
strSQL="SELECT TOP 3 Key, quote, Rnd(" & -1 * (intRandomNumber)&"*Key)" & "FROM Results " & "ORDER BY 3"
objConn.Open
Set objRS=objConn.Execute(strSQL)
%>