conn1.asp

来自「asp+access的电影免费网站源码是个很好的学习例子大家可以下来学习」· ASP 代码 · 共 70 行

ASP
70
字号
<!--#include file="ads.ini" -->

<%
	'如果使用国外主页空间,请使用下面语句:'
	'rem codepage="936"	'
	
	
	dim conn
	dim connstr
	dim db
	'更改数据库名字'
	db="../data/movie.mdb"
	on error resume next
	Set conn = Server.CreateObject("ADODB.Connection")

	if err then 
		err.clear
		errormsg="<BR><li>操作失败,无法创建数据库对象!"
		call disperrs(errormsg)
		response.end
	end if

	connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
	conn.Open connstr

	if err then 
		err.clear
		errormsg="<BR><li>操作失败,无法创建数据库连接!"
		call disperrs(errormsg)
		response.end
	end if


  	sub endConnection()
      		conn.close
      		set conn=nothing
  	end sub



	sub disperrs(errormsg)'出错提示'
	%>
	出错
	<%
	end sub

	Function SafeRequest(ParaName,ParaType) 
		'--- 传入参数 ---防止SQL注入 '
		'ParaName:参数名称-字符型' 
		'ParaType:参数类型-数字型(1表示以上参数是数字,0表示以上参数为字符)' 
		
		Dim ParaValue 
		ParaValue = Request(ParaName) 
		If ParaType = 1 then 
			If not isNumeric(ParaValue) then 
				Response.write "参数" & ParaName & "必须为数字型!" 
				Response.end 
			End if 
		Else 
			ParaValue=replace(ParaValue,"","") 
		End if 
		SafeRequest=ParaValue 
	End function 

	function connClose'关闭数据库
		Conn.close
		Set conn = Nothing
	End Function

%>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?