asp

位置:IT落伍者 >> asp >> 浏览文章

asp能用数据库操作类


发布日期:2023年08月06日
 
asp能用数据库操作类

Sub DeleteObject(ByRef obj)
Set obj = nothing
obj = null
End Sub

Class CDB
private m_oConn m_oRS
private m_pageIndex m_pageSize m_pageCount m_recordCount

private strError
private m_QueryString

private Sub Class_Initialize()
m_oConn = null
m_oRS = null

m_pageIndex =
m_pageSize =
m_pageCount =
m_recordCount =
Call connect()
End Sub

private property Get GetConnectionString()
if InStr(LCase(RequestServerVariables("SCRIPT_NAME")) "/admin/") > then
GetConnectionString = "Provider=microsoftjetoledb;data source=" & ServerMapPath("DataBasedatamdb")
else
GetConnectionString = "Provider=microsoftjetoledb;data source=" & ServerMapPath("AdminDataBasedatamdb")
end if
end property

public property Let SetPageSize(num)
if Not isNumeric(num) then Exit property
num = CInt(num)
if num > Then m_pageSize = num
End property

objectAppendSearch(paraName) = paraValue
public property Let AppendQueryString(paraName paraValue)
m_QueryString = m_QueryString & "&" & paraName & "=" & ServerURLEncode(paraValue)
end property

public property Let SetPageIndex(num)
if Not isNumeric(num) then Exit property
num = CInt(num)
if num > then m_pageIndex = num
End property

public default function toString()
toString = strError
end function

private sub Connect()
Set m_oConn = ServerCreateObject("ADODBConnection")
m_oConnConnectionString = GetConnectionString
m_oConnOpen()
if err then
strError = errDescription
Responsewrite("Sorry failed to connect Database!")
errClear()
DeleteObject(m_oConn)
ResponseEnd()
end if
end sub

private sub Close(ByRef DBObject)
if = DBObjectstate then Call DBObjectClose()
end sub

public function ExecuteScalar(strSql)
ExecuteScalar = m_oConnExecute(strSql)()
end function

public sub Execute(ByVal strSql)
if (Not isObject(m_oConn)) then Exit Sub
m_oConnExecute(strSql)
end sub

private function OpenRS()
OpenRS = false
if ((Not isObject(m_oConn)) Or m_oConnState = ) then exit function

if (isObject(m_oRS)) then
if = m_oRSState then Call m_oRSClose()
else
Set m_oRS = ServerCreateObject("ADODBRecordSet")
end if
OpenRS = true
end function

public function GetData(ByVal strSql)
if not OpenRS() then
GetData = null
exit function
end if
call m_oRSOpen(strSql m_oConn )

if m_oRSEOF then
GetData = null
else
GetData = m_oRSGetRows()
end if
m_oRSClose()
end function

public function GetMultPageData(ByVal strSQL)
if Not OpenRS() then
GetMultPageData = null
exit function
end If

Call m_oRSOpen(strSQL m_oConn )

if m_oRSEOF then
GetMultPageData = null
else
m_oRSPageSize = m_pageSize
m_recordCount = m_oRSRecordCount
m_pageCount = m_oRSPageCount
if (m_pageIndex > m_pageCount) then m_pageIndex = m_pageCount
m_oRSAbsolutePage = m_pageIndex
GetMultPageData = m_oRSGetRows(m_pageSize)
end if

Call m_oRSClose()
end function

public function PageInfo(style)
Dim sHtml : set sHtml = new StringBuild
sHtmlSetValue = "<div id=""divPageNav"">"
call sHtmlAppendFormat("<label>共:{}记录当前:{}/{}:</label>" Array(m_recordCount m_pageIndex m_pageCount))
Select Case style
Case : if = m_pageIndex then
call sHtmlAppend("<span>首页</span><span>上页</span>")
else
call sHtmlAppendFormat("<a href=""?page={}"">首页</a><a href=""?page={}{}"">上页</a>" Array(m_QueryStringm_pageIndex ))
end if
if m_pageCount = m_pageIndex then
call sHtmlAppend("<span>下页</span><span>尾页</span>")
else
call sHtmlAppendFormat("<a href=""?page={}{}"">下页</a><a href=""?page={}{}"">尾页</a>" Array(m_QueryString m_pageIndex + m_pageCount))
end if
Case : dim interval startPage endPage i
interval =
startPage = m_pageIndex interval
if startPage < then startPage =
endPage = startPage + * interval
if endPage > m_pageCount then endPage = m_pageCount
startPage = endPage * interval
if startPage < then startPage =

if = m_pageIndex then
call sHtmlAppend("<span style=""fontfamily: Webdings;""></span><span style=""fontfamily: Webdings;""></span>")
else
call sHtmlAppendFormat("<a href=""?page={}"" style=""fontfamily: Webdings;""></a><a href=""?page={}{}"" style=""fontfamily: Webdings;""></a>" Array(m_queryString CStr(m_pageIndex )))
end if
for i = startPage to m_pageIndex
call sHtmlAppendFormat("<a href=""?page={}{}"">{}</a>" Array( m_queryString CStr(i)))
next
call sHtmlAppend("<span>" & m_pageIndex & "</span>")
for i = m_pageIndex+ to endPage
call sHtmlAppendFormat("<a href=""?page={}{}"">{}</a>" Array( m_queryString CStr(i)))
next

if m_pageCount = m_pageIndex then
sHtmlAppend("<span style=""fontfamily:Webdings;""></span><span style=""fontfamily:Webdings;"">:</span>")
else
call sHtmlAppendFormat("<a href=""?page={}{}"" style=""fontfamily: Webdings;""></a><a href=""?page={}{}"" style=""fontfamily: Webdings;"">:</a>" Array(m_queryStringm_pageIndex+m_pageCount))
end if
end Select
call sHtmlAppend("</div>")
PageInfo = sHtml
DeleteObject(sHtml)
end function

private Sub Class_Terminate()
Close(m_oRS)
Close(m_oConn)
DeleteObject(m_oRS)
DeleteObject(m_oConn)
End Sub
end Class

dim i oDB arrData : set oDB = new CDB
oDBSetPageSize =
oDBSetPageIndex = RequestQueryString("page")
arrData = oDBGetMultPageData("SELECT [TITLE] FROM [CLASS]")
for i = to ubound(arrData )
echo(arrData( i) & "<br/>")
next
echo(oDBPageInfo())
DeleteObject(oDB)

               

上一篇:asp删除字符串所有空格函数

下一篇:asp无限级分类支持js收缩伸展