Display Top N records from MS Access

posted by Scudyen date: Thursday, May 22, 2008 category: ASP
  Featured Story | Printable View | Email It | Comments | Write Comment

This sample ASP code will give us a good idea how to display top 10 records, if we are using MS Access. Because MS Access database has got some limitations which we can not choose a limited data rows from complete database table. Of couse if you using SQL server, there is no any limitations.


If you try this code with MS Access database, it will fail.

<%
set con = server.createobject("adodb.connection")
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/db/mydb.mdb")
set rec = con.execute("select top 10 * from mytable")
%>

Script will fail unless you are not using SQL server. This is correct version which display only 10 records.


<%
set con = server.createobject("adodb.connection")
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/db/mydb.mdb")
set rec = con.execute("select top 10 *  from(select  * from mytable)")
%>


Do not forget to change table name and edit connection string.

Have a nice coding !




Custom Search



Gazatem Technologies Active News Manager


page counter

Listed with 411asp.net
Listed with 4aspin.com
PHP, ASP, .NET, JSP Resources, Reviews