熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

asp提高篇:利用JSP的思想來做ASP

2022-06-13   來源: .NET編程 

  程序的功能有了個大體的框架其實可以自己添加一些功能比如開始的數據庫連接 可以先設置

  變量然後通過INIT() 來選擇不同類型的數據庫

  <%
On Error Resume Next
Class ConnEx
public ConnEx
public DBpath 數據庫路徑
public DBtype 數據庫類型 (Access) (SqlServer) (可擴充)
public ConnMethod 連接方式 (DSN非DSN)
public User
public Pass
Sub Class_initialize
End Sub

  Sub Init()
ConnStr = Driver={Microsoft Access Driver (*mdb)};dbq=&ServerMapPath(Datemdb)
Set ConnEx = ServerCreateobject(ADODBCONNECTION)
ConnExOpen ConnStr
CatchError(Class_Terminate)
End Sub

  Sub CatchError( Str )
If Err Then
ErrClear
Class_Terminate()
ResponseWrite(捕捉到錯誤程序結束!在&Str&)
ResponseEnd()
End If
End Sub

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

  Function HasRecordBySql( Sql )
Call CheckSql(SqlR)
Dim RsHasR
Set Rs = ConnExExecute( Sql )
CatchError(HasReordSql)
If Not (Rseof Or Rsbof) Then
HasR = False
Else
HasR = True
End If
RsClose
Set Rs = Nothing
HasRecordBySql = HasR
End Function

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

  Function HasRecordById( StrTableName IntID )
CheckValue( IntID )
Dim RsHasR
Sql = Select top * from &StrTableName& Where Id = &IntID
Call CheckSql(SqlR)
Set Rs = ConnExExecute(Sql)
CatchError(HasRecordByID)
If Not (Rseof Or Rsbof) Then
HasR = False
Else
HasR = True
End If
Rsclose
Set Rs = Nothing
HasRecordById = HasR
End Function

  **********************************************
*通過SQL語句取得記錄集
**********************************************
Function GetRsBySql( Sql )
Call CheckSql(SqlR)
Dim Rs
Set Rs = ServerCreateObject(AdodbRecordSet)
RsOpen SqlConnEx
Set GetRsBySql = Rs
End Function

  *********************************************
*取得某個字段的值
*********************************************
Function GetValueBySql( Sql )
Call CheckSql(SqlR)
Dim RsReturnValue
Set Rs = ConnExExecute(Sql)
CatchError(GetValueBySql)
If Not( RsEof Or RsBof ) Then
ReturnValue = Rs()
Else
ReturnValue = 沒有記錄
End If
RsClose
Set Rs = Nothing
GetValueBySql = ReturnValue
End Function

  ======================UpdateInsert===================================

  *********************************************
*利用SQL修改數據
*********************************************
Function UpdateBySql( Sql )
Call CheckSql(Sqlw)
ConnExExecute(Sql)
CatchError(UpdateBySql)
UpdateBySql = True
End Function

  ********************************************
*利用SQL語句插入數據
********************************************
Function InsertBySql(Sql)
Call CheckSql(Sqlw)
ConnExExecute(Sql)
CatchError(InsertBySql)
InsertBySql = True
End Function

  ======================Delete========================================

  ********************************************
*通過SQL語句刪除
********************************************
Function DeleteBySql( Sql )
Call CheckSql(SqlD)
ConnExExecute(Sql)
CatchError(DeleteBySql)
DeleteBySql = True
End Function

  ********************************************
*檢查SQL語句權限根據標志Flag 來檢測語句擁有的權限
********************************************
Sub CheckSql( Sql Flag )
Dim StrSqlSinCountsDouCountsi
StrSql = Lcase(Sql)
SinCounts =
DouCounts =
For i = to Len(StrSql)
If Mid(StrSqli) = Then SinCounts = SinCounts +
If Mid(StrSqli) = Then DouConnts = DouCounts +
Next

  If (SinCounts Mod ) <> Or (DouCounts Mod ) <> Or Instr(StrSql;) > Then
Call Class_Terminate()
ResponseWrite(SQL語法錯誤!)
ResponseEnd()
End If
Select Case Flag
Case Rr:
If Instr(StrSqldelete) > Or Instr(StrSqlupdate) Or Instr(StrSqldrop) > Or Instr(StrSqlinsert) > Then
Class_Terminate()
ResponseWrite(權限不足沒有執行寫操作的權限)
ResponseEnd()
End If
Case Ww:
If Instr(StrSqldelete) > Or Instr(StrSqldrop) > Or Instr(StrSqlselect) > Then
Class_Terminate()
ResponseWrite(權限不足沒有執行刪除操作的權限)
ResponseEnd()
End If
Case Dd:
Case Else:
ResponseWrite(函數CheckSql標志錯誤!)
End Select
End Sub

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


From:http://tw.wingwit.com/Article/program/net/201311/11318.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.