Comparison of several open Recordset methods in ASP

Source: Internet
Author: User
Tags chr comparison include sort
Comparison | recordset

Define conn.asp First
<%
Dim objconn
Dim strconn
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Chr (+) & Server.MapPath ("Data.mdb") & Chr (34)
Set objconn = Server.CreateObject ("Adodb.connection")
objConn.Open strconn
%>

Let's look at several different ways to open recordsets (recordsets)

Mode 1,
Dim sql
Dim objRS

sql = "SELECT * FROM table1"
Set objRS = objConn.Execute (SQL)

This way, by executing SQL, the recordset is returned, and the filtered recordset is relatively simple.
However, the recordset obtained in this way cannot be paged out.

File text1.asp

<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<!--#include file= "conn.asp"-->

<%
Dim sql
Dim objRS

sql = "SELECT * FROM table1"
Set objRS = objConn.Execute (SQL)

Objrs.pagesize = 5
Objrs.absolutepage = 1
%>

The result of requesting this page is:

------------------------------------------------------------
Error type:
ADODB. Recordset (0X800A0CB3)
The current recordset does not support bookmarks. This may be a limitation of the provider or the selected cursor type.
/msg/test1.asp, line 12th.


Browser type:
mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1. NET CLR 1.1.4322)

Web page:
Get/msg/test1.asp

Time:
September 21, 2005, 19:58:01
------------------------------------------------------------

Mode 2,
Dim objRS
Set objRS = Server.CreateObject ("ADODB. Recordset ")
Objrs.open "Table1", objconn, 1, 2

Records opened in this manner can be paged out.

<%
Dim objRS

Set objRS = Server.CreateObject ("ADODB. Recordset ")
Objrs.open "Table1", objconn, 1, 2

Objrs.pagesize = 5
Objrs.absolutepage = 1
%>

Try it with this, haha, run smoothly.

But in this way open recordsets cannot be sorted

File test2.asp

<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<!--#include file= "conn.asp"-->
<%
Dim objRS

Set objRS = Server.CreateObject ("ADODB. Recordset ")
Objrs.open "Table1", objconn, 1, 2

Objrs.sort = "Field1"
%>

The result of requesting this page is:

------------------------------------------------------------
Error type:
ADODB. Recordset (0X800A0CB3)
The current provider does not support the interface required for sorting or filtering.
/msg/test2.asp, line 17th.


Browser type:
mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1. NET CLR 1.1.4322)

Web page:
Get/msg/test2.asp

Time:
September 21, 2005, 20:17:32
------------------------------------------------------------

What do we do?

Ah, that'll do.

<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<!--#include file= "conn.asp"-->
<%
Dim objRS

Set objRS = Server.CreateObject ("ADODB. Recordset ")
Objrs.cursorlocation = 3
Objrs.open "Table1", objconn, 1, 2

Objrs.sort = "Field1 desc"
%>

To sum up:
1, Mode 1, you can use SQL statements to easily filter the records you want.
2, Mode 2, the function is more powerful, but more complex.
There are more useful uses in this way. See other reference materials for details.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.