ASP Components Intermediate Getting Started with Examination Series

xiaoxiao2021-03-06  40

I have been busy this time, huh, huh

Today, let's take a look at a complete data package, with a paging example

Open VB6, create a new ActiveX DLL project. The engineering name is modified to FCOM, and the class name is modified to FZ8 reference "Microsoft Active Server Pages Object", "Microsoft ActiveX Data Object 2.7 Library" object library.

Create two component events: OnStartPage and OneundPage Create a reference to the class ScriptingContent in the event onstartpage. Instantiated class scriptingcontent.

code show as below:

Option expedition

'********************************************************** *

'Author: Tornado

'Features: Simple and fully packaged components

'time:

2005-01-01

'********************************************************** *

'Statement of the object

DIM MyResponse as response

DIM MyRequest as Request

DIM MyApplication AS Application

DIM MyServer As Server

DIM MySession as session

'Private variable

PRIVATE MPAGESIZE AS Long

Private mstrsql as string

'When the component is created, this event will be triggered.

Public Sub onstartPage (MyScriptingContent as scriptingcontext)

'Instantiation of objects

Set myresponse = myscriptingContent.response

Set myRequest = myscriptingcontent.request

Set myserver = myscriptingContent.server

SET myApplication = myscriptingcontent.application

Set mysession = myscriptingContent.Session

End Sub

'Trigger this event when the component is destroyed

Public Sub OneendPage ()

'Destroying object

Set myresponse = Nothing

Set myRequest = Nothing

Set myserver = Nothing

Set myapplication = Nothing

Set mysession = Nothing

End Sub

'Display Table

Public function showtable ()

DIM CONN As New Adodb.connection

DIM RS As New Adodb.Recordset

DIM I as integer

DIM J AS INTEGER

DIM INTPAGE AS INTEGER

DIM INTPAGECUNT AS INTEGER

DIM STRScriptName As String

DIM INTPOS AS INTEGER

DIM INTFIELDCOUNT AS INTEGER

'Get the path

strscriptname = myRequest.serverVariables ("script_name")

INTPOS = INSTRREV (strscriptname, "/")

IF INTPOS <> 0 THEN

STRSCRIPTNAME = MID (strscriptname, INTPOS 1) Endiff

IF ISempty (MyRequest ("Page")).

INTPAGE = 1

Else

INTPAGE = CINT (MyRequest ("Page"))

END IF

ON Error Goto ERR

Conn.open "provider = SQLOLEDB.1; PERSIST security info = false; user ID = sa; initial catalog = northwind; data source = localhost"

RS.Open MSTRSQL, CONN, AdopenStatic, AdlockReadonly

'Get the number of records

INTFIELDCOUNT = rs.fields.count

'Output form

MyResponse.write "

"

IF not r.

rs.pagesize = mpagesize

rs.absolutepage = INTPAGE

'Get the number of pages

INTPAGECUNT = rs.pagecount

'Treatment Page

IF INTPAGE <1 THEN INTPAGE = 1

IF INTPAGECOUNTPAGE = INTPAGECUNT

'Output header

MyResponse.write "

"

For i = 0 to intfieldcount - 1

MyResponse.write "

"

For j = 0 to intfieldcount - 1

MyResponse.write "

"

IF INTPAGE <> 1 THEN

MyResponse.write "

MyResponse.write " [Previous]

END IF

IF INTPAGE <> INTPAGECUNT THEN

MyResponse.write " [Next] [Last page]

END IF

MyResponse.write Page: "& INTPAGE &" & INTPAGECUNT & ""

MyResponse.write ""

END IF

MyResponse.write ""

'Release resources

IF not rs is nothing then

IF = 1 THEN

Rs.close

END IF

SET RS = Nothing

END IF

IF not conn is nothing then

IF conve.state = 1 THEN

Conn.close

END IF

Set conn = Nothing

END IF

EXIT FUNCTION

Err:

MyResponse.write Err.Number & Err.DESCRIption

IF not rs is nothing then

IF = 1 THEN

Rs.close

END IF

SET RS = Nothing

END IF

IF not conn is nothing then

IF conve.state = 1 THEN

Conn.close

END IF

Set conn = Nothing

END IF

END FUNCTION

'Define properties

Public property Get Showpagesize () As Variant

Showpagesize = Mpagesize

End Property

Public property Let ShowpageSize (Byval VNewValue As Variant)

Mpagesize = VNewValue

End Property

Public property get strsql () AS VARIANT

strsql = mstrsql

End Property

Public property Let Strsql (Byval VNewValue As Variant)

MSTRSQL = VNewValue

End Property

Compiled into a DLL file, the system will automatically register.

Otherwise manually register RegSVR

32 f

: /Test/fcom.dll

test

Open Visual InterDev6.0 to generate a FZ8.asp file

<% @ Language = VBScript%>

<%

DIM OBJ

Set obj = server.createObject ("fcom.fz8")

'Record of each page

Obj.showpagesize = 10

'Displayed SQL statement

Obj.strsql = "SELECT Customerid, CompanyName, ContactName, ContactTitle, Address from customers" obj.showtable ()

%>

Configure a virtual directory, perform FC8.asp files in IE, you can see http://blog.9cbs.net/online/gallery/image/42331.aspx

转载请注明原文地址:https://www.9cbs.com/read-74032.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.045, SQL: 9
" & RS (i) .Name & ""

NEXT

MyResponse.write ""

'Output content

For i = 1 to Mpagesize

IF r.eof then

EXIT for

END IF

MyResponse.write "

" & rs.fields (j) .Value & ""

NEXT

MyResponse.write ""

rs.movenext

NEXT

'Output paging

MyResponse.write "