How to retrieve a random records in ASP.NET
Posted on December 6, 2007 by tobject
Recently i needed to pull some random records from the database. One of the proposed solutions was something like this:
<asp:sqldatasource id=”SqlDataSource1″ runat=”server” connectionstring=”Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyName\MyDBfolder\DBfile.mdb” providername=”System.Data.OleDb” selectcommand=”SELECT TOP 1 *, Rnd([id]) AS Expr1 FROM Books ORDER BY Rnd([id]) DESC”></asp:sqldatasource>
This works in the query builder but not when you run the application.
The reason that this doesn’t work [...]
Filed under: ASP.NET | Tagged: SQL, SQL Server, Visual Studio | No Comments »