最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

ASP技巧:利用JSP的思想来做ASP

日期:10-20    来源:中国设计秀    作者:cnwebshow.com

   程序的功能有了个大体的框架,其实可以自己添加一些功能,比如开始的数据库连接 ,可以先设置sct中国设计秀

变量然后通过INIT() 来选择不同类型的数据库sct中国设计秀

<% sct中国设计秀
’On Error Resume Next sct中国设计秀
Class ConnEx sct中国设计秀
public ConnEx sct中国设计秀
public DBpath ’---------数据库路径 sct中国设计秀
public DBtype ’---------数据库类型 1(access) 2(SqlServer) 3(可扩充) sct中国设计秀
public ConnMethod ’--------连接方式 (DSN,非DSN) sct中国设计秀
public User sct中国设计秀
public Pass sct中国设计秀
Sub Class_initialize sct中国设计秀
End Subsct中国设计秀

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

Sub CatchError( Str ) sct中国设计秀
If Err Then sct中国设计秀
Err.Clear sct中国设计秀
Class_Terminate() sct中国设计秀
Response.Write("捕捉到错误,程序结束!在"&Str&"处") sct中国设计秀
Response.End() sct中国设计秀
End If sct中国设计秀
End Subsct中国设计秀

’****************************************** sct中国设计秀
’*通过SQL语句来查找记录是否存在,容易出错 sct中国设计秀
’******************************************sct中国设计秀

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

’*************************************** sct中国设计秀
’*通过ID来查找记录是否存在 sct中国设计秀
’***************************************sct中国设计秀

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

’********************************************** sct中国设计秀
’*通过SQL语句取得记录集 sct中国设计秀
’********************************************** sct中国设计秀
Function GetRsBySql( Sql ) sct中国设计秀
Call CheckSql(Sql,"R") sct中国设计秀
Dim Rs sct中国设计秀
Set Rs = Server.CreateObject("Adodb.RecordSet") sct中国设计秀
Rs.Open Sql,ConnEx,1,1 sct中国设计秀
Set GetRsBySql = Rs sct中国设计秀
End Functionsct中国设计秀

’********************************************* sct中国设计秀
’*取得某个字段的值 sct中国设计秀
’********************************************* sct中国设计秀
Function GetValueBySql( Sql ) sct中国设计秀
Call CheckSql(Sql,"R") sct中国设计秀
Dim Rs,ReturnValue sct中国设计秀
Set Rs = ConnEx.Execute(Sql) sct中国设计秀
CatchError("GetValueBySql") sct中国设计秀
If Not( Rs.Eof Or Rs.Bof ) Then sct中国设计秀
ReturnValue = Rs(0) sct中国设计秀
Else sct中国设计秀
ReturnValue = "没有记录" sct中国设计秀
End If sct中国设计秀
Rs.Close sct中国设计秀
Set Rs = Nothing sct中国设计秀
GetValueBySql = ReturnValue sct中国设计秀
End Functionsct中国设计秀

’============================Update,Insert====================sct中国设计秀

’********************************************* sct中国设计秀
’*利用SQL修改数据 sct中国设计秀
’********************************************* sct中国设计秀
Function UpdateBySql( Sql ) sct中国设计秀
Call CheckSql(Sql,"w") sct中国设计秀
ConnEx.Execute(Sql) sct中国设计秀
CatchError("UpdateBySql") sct中国设计秀
UpdateBySql = True sct中国设计秀
End Functionsct中国设计秀

’******************************************** sct中国设计秀
’*利用SQL语句插入数据 sct中国设计秀
’******************************************** sct中国设计秀
Function InsertBySql(Sql) sct中国设计秀
Call CheckSql(Sql,"w") sct中国设计秀
ConnEx.Execute(Sql) sct中国设计秀
CatchError("InsertBySql") sct中国设计秀
InsertBySql = True sct中国设计秀
End Functionsct中国设计秀

’=====================Delete=====================sct中国设计秀

’******************************************** sct中国设计秀
’*通过SQL语句删除 sct中国设计秀
’******************************************** sct中国设计秀
Function DeleteBySql( Sql ) sct中国设计秀
Call CheckSql(Sql,"D") sct中国设计秀
ConnEx.Execute(Sql) sct中国设计秀
CatchError("DeleteBySql") sct中国设计秀
DeleteBySql = True sct中国设计秀
End Functionsct中国设计秀

’******************************************** sct中国设计秀
’*检查SQL语句权限,根据标志Flag 来检测语句拥有的权限 sct中国设计秀
’******************************************** sct中国设计秀
Sub CheckSql( Sql , Flag ) sct中国设计秀
Dim StrSql,SinCounts,DouCounts,i sct中国设计秀
StrSql = Lcase(Sql) sct中国设计秀
SinCounts = 0 sct中国设计秀
DouCounts = 0 sct中国设计秀
For i = 1 to Len(StrSql) sct中国设计秀
If Mid(StrSql,i,1) = "’" Then SinCounts = SinCounts + 1 sct中国设计秀
If Mid(StrSql,i,1) = """" Then DouConnts = DouCounts + 1 sct中国设计秀
Nextsct中国设计秀

If (SinCounts Mod 2) <> 0 Or (DouCounts Mod 2) <> 0 Or Instr(StrSql,";") > 0 Then sct中国设计秀
Call Class_Terminate() sct中国设计秀
Response.Write("SQL语法错误!") sct中国设计秀
Response.End() sct中国设计秀
End If sct中国设计秀
Select Case Flag sct中国设计秀
Case "R","r": sct中国设计秀
If Instr(StrSql,"delete") > 0 Or Instr(StrSql,"update") Or Instr(StrSql,"drop") > 0 Or Instr(StrSql,"insert") > 0 Then sct中国设计秀
Class_Terminate() sct中国设计秀
Response.Write("权限不足,没有执行写操作的权限") sct中国设计秀
Response.End() sct中国设计秀
End If sct中国设计秀
Case "W","w": sct中国设计秀
If Instr(StrSql,"delete") > 0 Or Instr(StrSql,"drop") > 0 Or Instr(StrSql,"select") > 0 Then sct中国设计秀
Class_Terminate() sct中国设计秀
Response.Write("权限不足,没有执行删除操作的权限") sct中国设计秀
Response.End() sct中国设计秀
End If sct中国设计秀
Case "D","d": sct中国设计秀
Case Else: sct中国设计秀
Response.Write("函数CheckSql标志错误!") sct中国设计秀
End Select sct中国设计秀
End Subsct中国设计秀

Sub Class_Terminate sct中国设计秀
If Not IsEmpty(FriendConn) Then sct中国设计秀
FriendConn.Close sct中国设计秀
Set FriendConn = Nothing sct中国设计秀
CatchError() sct中国设计秀
End If sct中国设计秀
End Sub sct中国设计秀
End Class sct中国设计秀
%>sct中国设计秀

本文引用地址:/bc/article_46547.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明