Morpheusweb.it - Risorse per webmaster: script, ASP.NET, C#, Visual Basic .Net, tutorial, asp, javascript, css, php, html, java, ADO, VBScript, forms, frames, Active Server Pages, Dynamic HTML, database, gratis per webmaster e webdesigner

Random numbers

To extract a record from a database using a random number.
Estract the table elements and then I get a random number


<%
' query SQL
strSQLMax = "SELECT Max(ID) as MaxVal FROM tabella ORDER BY ID"
strSQL = "SELECT Top 1 ID, titolo FROM tabella Where ID = "
' open conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open strConn ' la stringa di conn
' get max number
Set rs = conn.Execute(strSQLMax)
intMax = rs("maxVal")
rs.Close
set rs = Nothing
' random number
Randomize()
intRandom = CInt ((Rnd() * intMax) + 1)
' get the record
Set rs = conn.Execute(strSQL & intRandom)
' show record
' ...
rs.Close
set rs = Nothing
conn.Close
set conn = Nothing
%>

Download code...


Print this page


 

Inizio pagina

risorse per webmaster