sub调用,请帮帮忙!谢谢!

来源:百度知道 编辑:UC知道 时间:2024/06/05 11:33:19
我的conn.asp中是这样写的:response.buffer=true
sub dblink()
strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("date/body.mdb")
set conn=server.createobject("adodb.connection")
conn.open strconn
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串。"
Response.End
End If
end sub
我要怎样才能在index.asp.中调用sub打开数据库
还是不行啊大哥
2 call dblink()
3 set rs=Server.CreateObject("adodb.recordset")
4 sql="SELECT * FROM list"
5 rs.Open sql,conn,1,3
6 response.write"<div id='menu'><ul>"
7 do while not rs.eof
8 Response.Write"<li><a href=""#"">"&rs(1)&"</a></li><li class=""menudiv""><img src=""images/s1/sg-3.jpg"" height=25 width=5></

在index.asp上的最上面加上

<!--#include file = "conn.asp"-->

之后

要打开数据库,写上

call dblink

以下为两个asp文件的内容
conn.asp:
<%
response.buffer=true
sub dblink()
On Error Resume Next
dim strconn
strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("date/body.mdb")
set conn=server.createobject("adodb.connection")
conn.open strconn
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串。"
Response.End
End If
end sub
%>

index.asp:

<%option explicit%>
<!--#include file = "conn.asp"-->
<%dim conn,rs,sql
call dblink()
set rs=Server.CreateObject("adodb.recordset")
sql="SELECT * FROM list"
rs.Open sql,conn,1,3

'.
'.
'.

%>