RE: Creating a Random Record? - 3/5/2001 20:25:00
<HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> <TITLE></TITLE> </HEAD> <BODY><% Dim objConn Set objConn = Server.CreateObject("ADODB.Connection") objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Documents and Settings\Administrator\Desktop\DF\DrawFlowApplication_Local\fpnwind.mdb;" objConn.Open Dim objRS Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open "SELECT employees.* FROM employees", objConn, _ adOpenStatic, adLockReadOnly Dim rndMax rndMax = CInt(objRS.RecordCount) objRS.MoveFirst 'Do until objRS.EOF ' Response.Write objRS("lastname") & "<BR>" 'objRS.MoveNext 'loop objRS.MoveFirst Dim rndNumber Randomize Timer rndNumber = Int(RND * rndMax) objRS.Move rndNumber Response.Write objRS("lastname") %> <BR> <table border=1> <tr> <td> <%= objRS("lastname")%> </td> <td> <%= objRS("firstname")%> </td> </tr>
O.K. forget the previous posts I misunderstood where you were trying to query from. I thought you were just writing a query in the database itself. You can take the code below change the cnstring to reflect the location of your database and you will need to replace the table and fields names that are referred to through out the rest of the code. This sample writes the last name out the page both in plain text and to table. EE <% objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing %> </table> </BODY> </HTML>
|