国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

利用JSP的思想來做ASP

2024-05-04 11:07:05
字體:
來源:轉載
供稿:網(wǎng)友

程序的功能有了個大體的框架,其實可以自己添加一些功能,比如開始的數(shù)據(jù)庫連接 ,可以先設置
  變量然后通過INIT() 來選擇不同類型的數(shù)據(jù)庫
  <%
  ’On Error Resume Next
  Class ConnEx
  public ConnEx
  public DBpath ’---------數(shù)據(jù)庫路徑
  public DBType ’---------數(shù)據(jù)庫類型 1(Access) 2(SqlServer) 3(可擴充)
  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("捕捉到錯誤,程序結束!在"&Str&"處")
  Response.End()
  End If
  End Sub

  ’******************************************
  ’*通過SQL語句來查找記錄是否存在,容易出錯
  ’******************************************

  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

  ’***************************************
  ’*通過ID來查找記錄是否存在
  ’***************************************

  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

  ’**********************************************
  ’*通過SQL語句取得記錄集
  ’**********************************************
  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

  ’*********************************************
  ’*取得某個字段的值
  ’*********************************************
  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 = "沒有記錄"
  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語句插入數(shù)據(jù)
  ’********************************************
  Function InsertBySql(Sql)
  Call CheckSql(Sql,"w")
  ConnEx.Execute(Sql)
  CatchError("InsertBySql")
  InsertBySql = True
  End Function

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

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

  ’********************************************
  ’*檢查SQL語句權限,根據(jù)標志Flag 來檢測語句擁有的權限
  ’********************************************
  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語法錯誤!")
  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("權限不足,沒有執(zhí)行寫操作的權限")
  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("權限不足,沒有執(zhí)行刪除操作的權限")
  Response.End()
  End If
  Case "D","d":
  Case Else:
  Response.Write("函數(shù)CheckSql標志錯誤!")
  End Select
  End Sub

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 抚顺市| 贡山| 河西区| 南召县| 金塔县| 正宁县| 泾阳县| 尼木县| 金山区| 屏山县| 连江县| 凌云县| 玛纳斯县| 临邑县| 漾濞| 九台市| 凤山县| 酒泉市| 奉节县| 荥阳市| 阳曲县| 肥城市| 双流县| 原阳县| 景德镇市| 福建省| 防城港市| 广德县| 五指山市| 汤原县| 延安市| 襄汾县| 师宗县| 屏边| 屯留县| 右玉县| 新安县| 垫江县| 南投县| 新建县| 山丹县|