小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

利用JSP的思想來(lái)做ASP

 duduwolf 2005-09-24
  程序的功能有了個(gè)大體的框架,其實(shí)可以自己添加一些功能,比如開(kāi)始的數(shù)據(jù)庫(kù)連接 ,可以先設(shè)置

變量然后通過(guò)INIT() 來(lái)選擇不同類型的數(shù)據(jù)庫(kù)

<%
’On Error Resume Next
Class ConnEx
public ConnEx
public DBpath ’---------數(shù)據(jù)庫(kù)路徑
public DBtype ’---------數(shù)據(jù)庫(kù)類型 1(Access) 2(SqlServer) 3(可擴(kuò)充)
public ConnMethod ’--------連接方式 (DSN,非DSN)
public User
public Pass
Sub Class_initialize
End Sub

Sub Init()
ConnStr = "Driver={Microsoft Access Driver (*.mdb)};dbq="&Server.MapPath("Date.mdb")
Set ConnEx = Server.Createobject("ADODB.CONNECTION")
ConnEx.Open ConnStr
CatchError("Class_Terminate")
End Sub

Sub CatchError( Str )
If Err Then
Err.Clear
Class_Terminate()
Response.Write("捕捉到錯(cuò)誤,程序結(jié)束!在"&Str&"處")
Response.End()
End If
End Sub

’******************************************
’*通過(guò)SQL語(yǔ)句來(lái)查找記錄是否存在,容易出錯(cuò)
’******************************************

Function HasRecordBySql( Sql )
Call CheckSql(Sql,"R")
Dim Rs,HasR
Set Rs = ConnEx.Execute( Sql )
CatchError("HasReordSql")
If Not (Rs.eof Or Rs.bof) Then
HasR = False
Else
HasR = True
End If
Rs.Close
Set Rs = Nothing
HasRecordBySql = HasR
End Function

’***************************************
’*通過(guò)ID來(lái)查找記錄是否存在
’***************************************

Function HasRecordById( StrTableName , IntID )
’CheckValue( IntID , 1 )
Dim Rs,HasR
Sql = "Select top 1 * from "&StrTableName&" Where Id = "&IntID
Call CheckSql(Sql,"R")
Set Rs = ConnEx.Execute(Sql)
CatchError("HasRecordByID")
If Not (Rs.eof Or Rs.bof) Then
HasR = False
Else
HasR = True
End If
Rs.close
Set Rs = Nothing
HasRecordById = HasR
End Function

’**********************************************
’*通過(guò)SQL語(yǔ)句取得記錄集
’**********************************************
Function GetRsBySql( Sql )
Call CheckSql(Sql,"R")
Dim Rs
Set Rs = Server.CreateObject("Adodb.RecordSet")
Rs.Open Sql,ConnEx,1,1
Set GetRsBySql = Rs
End Function

’*********************************************
’*取得某個(gè)字段的值
’*********************************************
Function GetValueBySql( Sql )
Call CheckSql(Sql,"R")
Dim Rs,ReturnValue
Set Rs = ConnEx.Execute(Sql)
CatchError("GetValueBySql")
If Not( Rs.Eof Or Rs.Bof ) Then
ReturnValue = Rs(0)
Else
ReturnValue = "沒(méi)有記錄"
End If
Rs.Close
Set Rs = Nothing
GetValueBySql = ReturnValue
End Function

’============================Update,Insert====================

’*********************************************
’*利用SQL修改數(shù)據(jù)
’*********************************************
Function UpdateBySql( Sql )
Call CheckSql(Sql,"w")
ConnEx.Execute(Sql)
CatchError("UpdateBySql")
UpdateBySql = True
End Function

’********************************************
’*利用SQL語(yǔ)句插入數(shù)據(jù)
’********************************************
Function InsertBySql(Sql)
Call CheckSql(Sql,"w")
ConnEx.Execute(Sql)
CatchError("InsertBySql")
InsertBySql = True
End Function

’=====================Delete=====================

’********************************************
’*通過(guò)SQL語(yǔ)句刪除
’********************************************
Function DeleteBySql( Sql )
Call CheckSql(Sql,"D")
ConnEx.Execute(Sql)
CatchError("DeleteBySql")
DeleteBySql = True
End Function

’********************************************
’*檢查SQL語(yǔ)句權(quán)限,根據(jù)標(biāo)志Flag 來(lái)檢測(cè)語(yǔ)句擁有的權(quán)限
’********************************************
Sub CheckSql( Sql , Flag )
Dim StrSql,SinCounts,DouCounts,i
StrSql = Lcase(Sql)
SinCounts = 0
DouCounts = 0
For i = 1 to Len(StrSql)
If Mid(StrSql,i,1) = "’" Then SinCounts = SinCounts + 1
If Mid(StrSql,i,1) = """" Then DouConnts = DouCounts + 1
Next

If (SinCounts Mod 2) <> 0 Or (DouCounts Mod 2) <> 0 Or Instr(StrSql,";") > 0 Then
Call Class_Terminate()
Response.Write("SQL語(yǔ)法錯(cuò)誤!")
Response.End()
End If
Select Case Flag
Case "R","r":
If Instr(StrSql,"delete") > 0 Or Instr(StrSql,"update") Or Instr(StrSql,"drop") > 0 Or Instr(StrSql,"insert") > 0 Then
Class_Terminate()
Response.Write("權(quán)限不足,沒(méi)有執(zhí)行寫操作的權(quán)限")
Response.End()
End If
Case "W","w":
If Instr(StrSql,"delete") > 0 Or Instr(StrSql,"drop") > 0 Or Instr(StrSql,"select") > 0 Then
Class_Terminate()
Response.Write("權(quán)限不足,沒(méi)有執(zhí)行刪除操作的權(quán)限")
Response.End()
End If
Case "D","d":
Case Else:
Response.Write("函數(shù)CheckSql標(biāo)志錯(cuò)誤!")
End Select
End Sub

Sub Class_Terminate
If Not IsEmpty(FriendConn) Then
FriendConn.Close
Set FriendConn = Nothing
CatchError()
End If
End Sub
End Class
%>

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多