Hi, as I've been looking for information about how to display a random record from an Access database, I keep running across your SQL statement above as replies to different messages. Would you mind to provide a little more information on how to utilize this? I am trying to display a random record from an access database. Right now there are 10 records. Just two columns ID and vFact (which is a string). This is the code I currently have:
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="randomfact.aspx.vb" Inherits="randomfact" %>
<%
@ Import Namespace="System.Data" %>
<%
@ Import Namespace="System.Data.OleDb" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml" >
<
head runat="server">
<title>Untitled Page</title>
<script language="VB" runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim connString As String
connString =
"PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + "C:\Database\QEI.mdb;"
Dim objConnection As OleDbConnectionobjConnection = New OleDbConnection(connString)
objConnection.Open()
Dim strSQL As String = "SELECT vFact FROM tFact ORDER BY Rnd(-10000000*TimeValue(Now())*[ID])"
Dim objCommand As OleDbCommandobjCommand = New OleDbCommand(strSQL, objConnection)
Dim objDataReader As OleDbDataReader
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
fact.DataSource = objDataReader
fact.DataBind()
objDataReader.Close()
End Sub
</
script> </head>
<
body>
<form id="form1" runat="server">
<div>
<asp:DataGrid id="fact" runat="server" />
<br /><br />
</div></form>
</
body>
</
html>Unfortunately, the SQL statement doesn't work. I get the error message: "No value given for one or more required parameters." on the code line:
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
Any idea what I am doing wrong? Thank you.
Holly