程序的功能有了个大体的框架其实可以自己添加一些功能比如开始的数据库连接 可以先设置
变量然后通过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
%>