M0194 Web-based Programming Lanjut Session 8 

advertisement
M0194
Web-based Programming Lanjut
Session 8
 2004 Tau Yenny, SI - Binus
2
ASP and Data on the Client




Disconnected Recordset
Remote Data Services (RDS)
Data Transfer between Server and Client
Recordset Paging
 2004 Tau Yenny, SI - Binus
3
Disconnected Recordset

A disconnected recordset is just a normal recordset, but its
connection to the server removed.

The recordset stands alone, can act like a normal recordset,
allowing updates, additions, and deletions.

But changes only happen in the recordset, are not reflected in
the server.

The connection to the server can be re-established and the
server updated with any changes

If data on the server has changed, you can detect these
changes. This is called conflict resolution.
 2004 Tau Yenny, SI - Binus
4
Remote Data Service (RDS)




RDS is the name given to the set of services
that allows us to handle data on the client.
RDS is part of ADO
Only comes into use when you need to
transfer and use data at the client
Made up from several components
 2004 Tau Yenny, SI - Binus
5
Remote Data Server
Client
Server
Name:
Client:
Data store
Data
Binding
Manager
OLE-DB
Provider
Data
Client
Cache
Data
Source
Object
DataSpace
Object
Network
DataFactory
Custom
Object
Component
Web
Server
 2004 Tau Yenny, SI - Binus
6
Remote Data Server

RDS Server Components

Data store

OLE DB Provider

Two option how work with the data


The DataFactory
The default server-side component, provides access to data stores

A Custom Component
A normal COM component that has methods to perform data transfer.
Web Server, acts as the interface between client and the
server.
 2004 Tau Yenny, SI - Binus
7
Remote Data Server

RDS Client Components

DataSpace Object

goes hand-in-hand with the DataFactory or a Custom Component, provides the clientside part of the equation.

DataSpace is a proxy object, responsible for the communication with the server, providing
the channel through which data is moved.

Created by using an HTML <OBJECT> tag.

Data Source Object (DSO)

Responsible for storing data on the client, contains an ADO Recordset and work together
with the Client Data Cache to manage the data

Created by using an HTML <OBJECT> tag

Client Data Cache

The client cursor service managing the data on the client

Data Binding Manager

Create the link (binding) between the HTML controls and the DSO. Perform by
specifying the DATASRC and DATAFLD attributes of certain HTML controls.
 2004 Tau Yenny, SI - Binus
8
Remote Data Server

Browser Support for RDS

Only works in Microsoft browsers
Fully supported on Microsoft Internet Explorer 4.0 and
above
Be aware, clients accessing application that rely on RDS
might have different versions with the server. For
example, IE4 shipped with RDS 1.5, while IE5,
Office2000 and Visual Studio 6 with RDS 2.0, Windows
2000 with RDS 2.5

Two ways to take care of compability problem :




Make sure all users upgrade to the latest version of RDS.
Specify the Data Factory Mode when connecting to data
source. Specify which version to use.
 2004 Tau Yenny, SI - Binus
9
Remote Data Server

Data Source Objects
Is a client-side object that stores and manages the data once it is on the
client.
Several different DSO :

Tabular Data Control (TDC) is design to manipulate data held in a tabular
or delimited from text files.

Remote Data Service Data Control is design to connect to OLEDB data
stores, and can specify where to connect to as well as which data to return

Java DataBase Connector is a Java applet that allows connection to data
stores through the Java DataBase Control (JDBC).

Microsoft HTML (MSHTML) DSO takes data marked up in HTML and uses
this as the source of the data.

XML DSO uses XML data, and can be used for either well-structured or
arbitrarily structured XML.
 2004 Tau Yenny, SI - Binus
10
Tabular Data Control


TDC is the simplest DSO, useful for small amounts of data that will
be read-only.
Created by placing an <OBJECT> tag
<OBJECT CLASSID=“clsid:333C7BC4-460F-11D0BC04-0080C7055A83”
ID=“dsoEmployee” WIDTH=“0” HEIGHT=“0”>
<PARAM NAME=“DataURL” Value=“Employee.csv”>
</OBJECT>
example of data in Comma Separated Values (CSV):
PMA42628M,"Paolo","M","Accorti",13,35,"0877",1992-08-27 00:00:00
PSA89086M,"Pedro","S","Afonso",14,89,"1389",1990-12-24 00:00:00
VPA30890F,"Victoria","P","Ashworth",6,140,"0877",1990-09-13 00:00:00
H-B39728F,"Helen"," ","Bennett",12,35,"0877",1989-09-21 00:00:00
L-B31947F,"Lesley"," ","Brown",7,120,"0877",1991-02-13 00:00:00
F-C16315M,"Francisco"," ","Chang",4,227,"9952",1990-11-03 00:00:00
 2004 Tau Yenny, SI - Binus
11
RDS Data Control




RDS Data Control provides access to normal data stores, as
opposed to flat files.
Most often used to connect to SQL database to retrieve data from
tables queries or stored procedures
Allow data to be update
Created using an HTML <OBJECT> tag
<OBJECT CLASSID=“clsid:BD96C556-65A3-11D0-983A-00C04FC29E33”
ID=“dsoAuthors” WIDTH=“0” HEIGHT=“0”>
<PARAM NAME=“Connect” Value=“Connection String”>
<PARAM NAME=“Server” Value=“Server Name”>
<PARAM NAME=“SQL” Value=“Query Text”>
</OBJECT>
 2004 Tau Yenny, SI - Binus
12
RDS Data Control

Example :
<OBJECT CLASSID=“clsid:BD96C556-65A3-11D0-983A-00C04FC29E33”
ID=“dsoAuthors” WIDTH=“0” HEIGHT=“0”>
<PARAM NAME=“Connect” Value=“DSN=pubs”>
<PARAM NAME=“Server” Value=“W2000”>
<PARAM NAME=“SQL” Value=“SELECT * FROM Authors”>
</OBJECT>

ADO 2.5 has a new URL property that allows to use file as the
source of data.
<OBJECT CLASSID=“clsid:BD96C556-65A3-11D0-983A-00C04FC29E33”
ID=“dsoAuthors” WIDTH=“0” HEIGHT=“0”>
<PARAM NAME=“URL” Value=“DataPage.asp”>
</OBJECT>
 2004 Tau Yenny, SI - Binus
13
RDS Data Control

The DataPage.asp file could contain the following VBScript code :
<!-- #include file="dataconn.inc" -->
<%
Dim rsData
Set rsData = Server.CreateObject (“ADODB.Recordset”)
rsData.Open “SELECT * FROM Authors”, strConn
rsData.Save Response, 1
‘ adPersistXML= 1
rsData.Close
Set rsData = Nothing
%>
 2004 Tau Yenny, SI - Binus
14
MSHTML Data Control






MSHTML is rather unusual – is part of IE
Allows to have a data source based on HTML.
MSHTML is not a form that naturally use for data storage
MSHTML could be useful if you have a lot of HTML pages that
do contain some data.
MSHTML data control has a Recordset property, but has no
methods.
Created by <OBJECT> tag
<OBJECT ID=“dsoAuthors” DATA=“Authors.html” HEIGHT=“0” WIDTH=“0”>
</OBJECT>
 2004 Tau Yenny, SI - Binus
15
MSHTML Data Control

To be able to use the control, your HTML tag must have an ID
attribute.
<DIV ID=“au_id”>172-32-1176</DIV>
<SPAN ID=“au_lname”>White</SPAN>
<H1 ID=“au_fname”>Bob</H1>
<PRE ID=“au_id”>213-46-8915</PRE>
<H2 ID=“au_lname”>Green</H2>
<H1 ID=“au_fname”>Cheryl</H1>


The example above show that the HTML tag names are irrelevant –
it’s the ID that is important.
The above HTML, would generate 2 rows of data, that looked like
this:
au_id
au_lname
au_fname
172-32-1176
White
Bob
213-46-8915
Green
Cheryl
 2004 Tau Yenny, SI - Binus
16
XML Data Control


The <XML> tag acts like a data control
Use the <XML> tag in one of two ways:

The first way, use the SRC attribute to specify the location of the
data
<XML ID=“dsoAuthors” SRC=“Authors.xml”></XML>

Alternatively, embed the XML in the tag
<XML ID=“dsoAuthors”>
<Authors>
<Author>
<au_id>172-32-1176</au_id>
<au_lname>White</au_lname>
<au_fname>Johnson</au_fname>
<phone>408 496-7223</phone>
<contract>True</contract>
</Author>
<Author>
<au_id>213-46-8915</au_id>
<au_lname>Green</au_lname>
<au_fname>Marjorie</au_fname>
<phone>415 986-7020</phone>
<contract>True</contract>
</Author>
</Authors>
</XML>
 2004 Tau Yenny, SI - Binus
17
Data Binding

Binding means setting up a relationship between some HTML elements
and the data control.



The data control is responsible for managing the data and supplying the
data to the HTML element
The element displays the data on the screen
To bind an HTML element to a data source, specify two attributes for it:

DATASRC, to identify the data control that contains the data. Always put
a # in front of the data source name.

DATAFLD, to identify the field in the data control to bind to. The fields
are the names identifying the columns in the data that the data control
manages.

DATAFORMATS, to indicate how the data in the field should formatted,
can be either HTML or TEXT. The default is TEXT
 2004 Tau Yenny, SI - Binus
18
Data Binding
<HTML>
<HEAD><TITLE>RDSSingleBinding.asp</TITLE></HEAD>
<BODY>
<H1>Data Binding with RDS<HR></H1>
<OBJECT CLASSID="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33"
ID="dsoAuthors" WIDTH="0" HEIGHT="0">
<PARAM NAME="URL" Value="DataPage.asp">
</OBJECT>
<DIV DATASRC="#dsoAuthors" DATAFLD="au_fname"></DIV>
<DIV DATASRC="#dsoAuthors" DATAFLD="au_lname"></DIV>
</BODY>
</HTML>
 2004 Tau Yenny, SI - Binus
19
Data Binding
1.
2.
3.
4.
5.
6.
7.
8.
9.
<HTML>
<HEAD><TITLE>TDCDataFormat.asp</TITLE></HEAD>
<BODY>
<H1>Data Formatting in bound data<HR></H1>
<OBJECT CLASSID="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83"
ID="dsoImages" WIDTH="0" HEIGHT="0">
<PARAM NAME="DataURL" Value="images.csv">
<PARAM NAME = "UseHeader" VALUE = "TRUE">
</OBJECT>
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
<TABLE ID="tblData" DATASRC="#dsoImages" BORDER="1">
<THEAD>
<TR>
<TD>Description</TD>
<TD>Image</TD>
</TR>
</THEAD>
<TBODY>
<TR>
<TD><SPAN DATAFLD="Description"></SPAN></TD>
<TD><SPAN DATAFLD="Image" DATAFORMATAS="HTML"></SPAN></TD>
</TR>
</TBODY>
</TABLE>
</BODY>
</HTML>
 2004 Tau Yenny, SI - Binus
20
Data Binding
Images.csv:
Description,Image
The asian cartoon,<IMG SRC=images\asian_cartoon.gif>
The Badz-maru,<IMG SRC=images\badtz-maru.gif>
The Businessman,<IMG SRC=images\biz_man.jpg>
 2004 Tau Yenny, SI - Binus
21
Table Binding

Table binding differs from single record binding, because we
bind to the TABLE element. This allows to see more than one
record at a time.

Table binding has one attribute useful to data binding –
DATAPAGESIZE. This determines how many records are
shown in the table
 2004 Tau Yenny, SI - Binus
22
Table Binding
1.
2.
3.
4.
5.
6.
7.
8.
<HTML>
<HEAD><TITLE>RDSTableBinding.asp</TITLE></HEAD>
<BODY>
<H1>Table Data Binding with RDS<HR></H1>
<OBJECT CLASSID="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33“
ID="dsoData" WIDTH="0" HEIGHT="0">
<PARAM NAME="URL" Value="DataPage.asp">
</OBJECT>
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
<TABLE ID="tblData" DATASRC="#dsoData" DATAPAGESIZE="5" >
<THEAD>
<TR>
<TD>au_id</TD>
<TD>au_fname</TD>
<TD>au_lname</TD>
<TD>phone</TD>
<TD>address</TD>
<TD>city</TD>
<TD>state</TD>
<TD>zip</TD>
<TD>contract</TD>
</TR>
</THEAD>
<TBODY>
<TR>
<TD><INPUT TYPE="TEXT" DATAFLD="au_id"></INPUT></TD>
<TD><INPUT TYPE="TEXT" DATAFLD="au_fname"></INPUT></TD>
<TD><INPUT TYPE="TEXT" DATAFLD="au_lname"></INPUT></TD>
<TD><INPUT TYPE="TEXT" DATAFLD="phone"></INPUT></TD>
<TD><INPUT TYPE="TEXT" DATAFLD="address"></INPUT></TD>
<TD><INPUT TYPE="TEXT" DATAFLD="city"></INPUT></TD>
<TD><INPUT TYPE="TEXT" DATAFLD="state"></INPUT></TD>
<TD><INPUT TYPE="TEXT" DATAFLD="zip"></INPUT></TD>
<TD><INPUT TYPE="TEXT" DATAFLD="contract"></INPUT></TD>
</TR>
</TBODY>
</TABLE>
</BODY>
</HTML>
 2004 Tau Yenny, SI - Binus
23
Table Binding
 2004 Tau Yenny, SI - Binus
24
Data Transfer Between Server and Client

Some problem we need to solve





We need a secure way to retrieve data from a server and
use it on the client
We need a way that allows data to be updated
We don’t want to compromise flexibility
The way around this problem is to use components.
A component allows us to encapsulate all of our
data access functionality, including the source of the
data, and ensures that data are only exposed to
Web page.
 2004 Tau Yenny, SI - Binus
25
Data Transfer Between Server and Client

A server based component
The component creator uses a programming language that can create
COM components specification. For example, Visual Basic(VB) or Visual
C++(VC++).
 The client has a programming language or tool (Such as Microsoft Word
or ASP) that know how to instantiate and use COM components, by
following the rules laid down in the COM specification.
Example – creating Book Component
Start Visual Basic and create a new ActiveX DLL project, changing the name
of the default class module to BookTitles.
Next, change the name of the project to Book.
Add a reference that we need in the project.

 2004 Tau Yenny, SI - Binus
1.
Option Explicit
2.
3.
Private mobjConn As ADODB.Connection
Private mrsBooks As ADODB.Recordset
4.
5.
6.
7.
8.
9.
'open the connection and recordset
Public Sub OpenTitles()
Set mobjConn = New ADODB.Connection
Set mrsBooks = New ADODB.Recordset
26
mobjConn.ConnectionString="Provider=SQLOLEDB; Data Source=hogwartz; Initial Catalog=pubs; User ID=sa; “ & _
“Password= letmein"
mobjConn.Open
10.
11.
12.
mrsBooks.CursorLocation = adUseClient
13.
mrsBooks.Open "SELECT * FROM Titles", mobjConn
14. End Sub
15. 'Close the list
16. Public Sub CloseTitles()
17.
'Close the recordset
18.
If Not (mrsBooks Is Nothing) Then
19.
If mrsBooks.State = adStateOpen Then
20.
mrsBooks.Close
21.
End If
22.
Set mrsBooks = Nothing
23.
End If
24.
'Close the connection
25.
If Not (mobjConn Is Nothing) Then
26.
mobjConn.Close
27.
Set mobjConn = Nothing
28.
End If
29. End Sub
 2004 Tau Yenny, SI - Binus
30. 'returns the next title
31. Public Sub NextTitle(Id As Variant, Title As Variant, Price As Variant, Notes As Variant)
32.
33.
'Ignore errors and more specifically null values in this demo
On Error Resume Next
34.
If IsEOF = True Then
35.
Err.Raise vbObject + 1, "BookTitles Component", "End of Cursor"
36.
Exit Sub
37.
End If
38.
39.
'Copy the fields back to the caller
40.
Id = mrsBooks.Fields("Title_id")
41.
Title = mrsBooks.Fields("Title")
42.
Price = mrsBooks.Fields("Price")
43.
Notes = mrsBooks.Fields("Notes")
44.
45.
'Move to the next title
46.
If Not mrsBooks.EOF Then mrsBooks.MoveNext
47. End Sub
48. Public Function IsEOF() As Boolean
49.
IsEOF = mrsBooks.EOF
50. End Function
If you tried defining the NextTitle procedure Parameter using the String and
Currency types, you’d get an error. Because the Active Scripting engine only
know the Variant type.
 2004 Tau Yenny, SI - Binus
27
28
Data Transfer Between Server and Client
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
<%
Dim objTitles
Set objTitles = Server.CreateObject("Book.BookTitles")
%>
<HTML><HEAD><TITLE>Titles List</TITLE></HEAD>
<BODY>
<H1>Book Titles</H1><HR>
<P>The following books are currently defined in the pubs database:
<TABLE cellspacing="2" cellpadding="0">
<TR> <TD bgcolor="#3AC2EF"><STRONG>ID</STRONG></TD>
<TD bgcolor="#3AC2EF"><STRONG>Title</STRONG></TD>
<TD bgcolor="#3AC2EF"><STRONG>Price</STRONG></TD>
<TD bgcolor="#3AC2EF"><STRONG>Notes</STRONG></TD> </TR>
<TR></TR>
<%
Dim strID
Dim strTitle
Dim strPrice
Dim strNotes
'Initialize the list
objTitles.OpenTitles
'Process each author
While objTitles.IsEOF = False
objTitles.NextTitle strID, strTitle, strPrice, strNotes
%>
<TR> <TD bgcolor="#FFFF6C"><%= strID %></TD>
<TD bgcolor="#FFFF6C"><%= strTitle %></TD>
<TD bgcolor="#FFFF6C"><%= strPrice %></TD>
<TD bgcolor="#FFFF6C"><%= strNotes %></TD></TR>
<%
Wend
%>
</TABLE></BODY></HTML>
 2004 Tau Yenny, SI - Binus
29
Data Transfer Between Server and Client
 2004 Tau Yenny, SI - Binus
30
Data Transfer Between Server and Client

Advantages of using Server Side Components




There are no connection details visible to the user – which
gives you a securer system. The component also has to be
specially registered, so there is the added security restriction.
You can build components in any COM compliant language.
We use VB in this example, because it’s easy to understand.
Your components isn’t limited to just returning and updating
recordsets but you could build in lots of logic.
You could encapsulate all of that conflict resolution code in the
Recordset method, and just return details of any errors. This
means your client-side script is neater and users can’t rip off
your hard-worked code.
 2004 Tau Yenny, SI - Binus
31
Recordset Paging

Using ADO Paging
1.
2.
3.
4.
5.
6.
7.
8.
9.
<%
Dim rsData
Dim intPage
Dim intTotalPages
Dim fldF
Dim intRec
Dim strQuote
Dim strScriptName
Dim strConn
10.
strConn = " Provider = SQLOLEDB; Data Source= Hogwartz; Initial Catalog= pubs; User ID= sa; Password=letmein"
11.
strQuote = Chr(34) 'the double quote character
12.
Set rsData = Server.CreateObject("ADODB.Recordset")
13.
14.
15.
'set the page size
rsData.PageSize = 10
rsData.CursorLocation = 3 'adUseClient=3
16.
17.
'Open the data
rsData.Open "Authors", strConn,0,1,2 'adOpenForwardOnly=0, adLockReadOnly=1, adCmdTable=2
 2004 Tau Yenny, SI - Binus
32
18. If Request.QueryString("PAGE")="" Then
19.
intPage=1
20. Else
21.
intPage = CInt( Request.QueryString("PAGE") )
22.
If intPage < 1 then
23.
intPage=1
24.
Else
25.
If intPage > rsData.PageCount Then
26.
intPage = rsData.PageCount
27.
Else
28.
intPage = CInt( Request.QueryString("PAGE") )
29.
End If
30.
End If
31. End If
32. rsData.AbsolutePage = intPage
33. Response.Write "Page = " & rsData.AbsolutePage & "<BR>"
34.
35.
36.
37.
38.
Response.Write "<TABLE BORDER=1><THEAD><TR>"
For Each fldF In rsData.Fields
Response.Write "<TD>" & fldF.Name & "</TD>"
Next
Response.Write "</TR></THEAD><TBODY>"
39. For intRec = 1 to rsData.PageSize
40.
If Not rsData.EOF Then
41.
Response.Write "<TR>"
42.
For Each fldF In rsData.Fields
43.
Response.Write "<TD>" & fldF.Value & "</TD>"
44.
Next
45.
Response.Write "</TR>"
46.
rsData.MoveNext
47.
End If
48. Next
49. Response.Write "</TBODY></TABLE></P>"
 2004 Tau Yenny, SI - Binus
50. strScriptName = Request.ServerVariables("SCRIPT_NAME")
51. Response.Write " <A HREF=" & strQuote & strScriptName & "?PAGE=1" & strQuote & "> First Page
</A>"
52. 'Only give an active previous page if there are previous page
53. If intPage= 1 Then
54.
Response.Write " <SPAN>Previous Page</SPAN>"
55. Else
56.
Response.Write " <A HREF=" & strQuote & strScriptName & "?PAGE="& intPage - 1 &
strQuote & "> Previous Page </A>"
57. End If
58. 'Only give an active next page if there are more pages
59. If intPage = rsData.PageCount Then
60.
Response.Write " <SPAN>Next Page</SPAN>"
61. Else
62.
Response.Write " <A HREF=" & strQuote & strScriptName & "?PAGE="& intPage + 1 &
strQuote & "> Next Page </A>"
63. End If
64. Response.Write " <A HREF=" & strQuote & strScriptName & "?PAGE=" & rsData.PageCount &
strQuote & "> LastPage </A>"
65. rsData.Close
66. Set rsData =Nothing
67. %>
 2004 Tau Yenny, SI - Binus
33
34
Recordset Paging
 2004 Tau Yenny, SI - Binus
35
Recordset Paging

Using SQL Server
CREATE PROCEDURE usp_PagedAuthors
@iPage
int,
@iPageSize int
AS
BEGIN
SET NOCOUNT ON
-- disable row counts
-- declare variables
DECLARE @iStart
DECLARE @iEnd
DECLARE @iPageCount
int
int
int
-- start record
-- end record
-- total number of pages
CREATE TABLE #PagedAuthors
-- create the temporary table
(
ID
int
IDENTITY,
au_id
varchar(11)
NOT NULL,
au_lname varchar(40) NOT NULL,
au_fname varchar(20) NOT NULL,
phone
char(12)
NOT NULL,
address
varchar(20) NULL,
city
varchar(20) NULL,
state
char(2)
NULL,
zip
char(5)
NULL,
contract
bit
NOT NULL
)
 2004 Tau Yenny, SI - Binus
-- populate the temporary table
INSERT INTO #PagedAuthors (au_id, au_lname, au_fname, phone, address, city, state, zip, contract)
SELECT au_id, au_lname, au_fname, phone, address, city, state, zip, contract
FROM authors
-- work out how many pages there are in total
SELECT @iPageCount = COUNT(*)
FROM authors
SELECT @iPageCount = 3
-- check the page number
IF @iPage < 1
SELECT @iPage = 1
IF @iPage > @iPageCount
SELECT @iPage = @iPageCount
-- calculate the start and end records
SELECT @iStart = (@iPage - 1) * @iPageSize
SELECT @iEnd = @iStart + @iPageSize +1
-- select only those records that fall within our page
SELECT au_id, au_lname, au_fname, phone, address, city, state, zip, contract
FROM #PagedAuthors
WHERE ID > @iStart
AND
ID < @iEnd
DROP TABLE #PagedAuthors
SET NOCOUNT OFF
-- turn back on record counts
RETURN @iPageCount
END
 2004 Tau Yenny, SI - Binus
36
37
Recordset Paging
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
<HTML><HEAD><TITLE>SQL Paging</TITLE></HEAD>
<BODY>
<%
Dim rsData
Dim intPage
Dim intLastPage
Dim fldF
Dim cmdAuthors
Dim strQuote
Dim strScriptName
Dim strConn
12. strConn="Provider=SQLOLEDB;Data Source=Hogwartz;Initial Catalog=pubs;User ID=sa; Password=letmein"
13. strQuote = Chr(34) 'the double quote character
14. If Request.QueryString("PAGE")="" Then
15.
intPage=1
16. Else
17.
intPage = CInt( Request.QueryString("PAGE") )
18.
If intPage < 1 then
19.
intPage=1
20.
End If
21. End If
22. Set cmdAuthors = Server.CreateObject("ADODB.Command")
23. Set rsData = Server.CreateObject("ADODB.Recordset")
 2004 Tau Yenny, SI - Binus
38
24. With cmdAuthors
25.
.ActiveConnection = strConn
26.
.CommandText = "usp_PagedAuthors"
27.
.CommandType = 4 'adCmdStoredProc=4
28.
29.
30.
.Parameters.Append .CreateParameter("RETURN_VAL", 3, 4) 'adInteger=3 adParamReturnValue=4
.Parameters.Append .CreateParameter("@iPage", 3, 1, 8, intPage) 'adInteger=3 adParamInput=1
.Parameters.Append .CreateParameter("@iPageSize", 3, 1, 8, 10) 'adInteger=3 adParamInput=1
31.
32.
Set rsData = .Execute
.Execute
33.
intLastPage = .Parameters("RETURN_VAL")
34. End WIth
35. Response.Write "Page = " & intPage & "<BR>“
36.
37.
38.
39.
40.
Response.Write "<TABLE BORDER=1><THEAD><TR>"
For Each fldF In rsData.Fields
Response.Write "<TD>" & fldF.Name & "</TD>"
Next
Response.Write "</TR></THEAD><TBODY>"
41. For intRec = 1 to rsData.PageSize
42.
If Not rsData.EOF Then
43.
Response.Write "<TR>"
44.
For Each fldF In rsData.Fields
45.
Response.Write "<TD>" & fldF.Value & "</TD>"
46.
Next
47.
Response.Write "</TR>"
48.
rsData.MoveNext
49.
End If
50. Next
51. Response.Write "</TBODY></TABLE></P>"
 2004 Tau Yenny, SI - Binus
52. strScriptName = Request.ServerVariables("SCRIPT_NAME")
53. Response.Write " <A HREF=" & strQuote & strScriptName & "?PAGE=1" & strQuote & "> First Page
</A>"
54. 'Only give an active previous page if there are previous page
55. If intPage= 1 Then
56.
Response.Write " <SPAN>Previous Page</SPAN>"
57. Else
58.
Response.Write " <A HREF=" & strQuote & strScriptName & "?PAGE="& intPage - 1 &
strQuote & "> Previous Page </A>"
59. End If
60. 'Only give an active next page if there are more pages
61. If intPage = intLastPage Then
62.
Response.Write " <SPAN>Next Page</SPAN>"
63. Else
64.
Response.Write " <A HREF=" & strQuote & strScriptName & "?PAGE="& intPage + 1 &
strQuote & "> Next Page </A>"
65. End If
66. Response.Write " <A HREF=" & strQuote & strScriptName & "?PAGE=" & intLastPage & strQuote &
"> LastPage </A>"
67.
68.
69.
70.
71.
72.
rsData.Close
Set rsData =Nothing
Set cmdAuthors = Nothing
%>
</BODY>
</HTML>
 2004 Tau Yenny, SI - Binus
39
40
Recordset Paging
 2004 Tau Yenny, SI - Binus
Download