数据库连接错哪了?

anjinzhe 2005-05-12 08:40:53
数据库连接文件 conn.asp
<%
set conn=server.createobject("adodb.connection")
conn.open="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.mappath("student.mdb")
%>
index.asp文件
<!-- include file="conn.asp" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> 数据库检索的例子 </TITLE>
</HEAD>

<BODY bgcolor="#0099FF">
<center>
<%
set rs=server.createobject("adodb.recordset")
sqlstmt="select * from student"
rs.open sqlstmt,conn
if rs.eof then
response.write "<center>数据库中没有记录,"
response.write "<br>请检查数据库!</center>"
else
%>
<h1><b><i>检索数据库记录的例子</i></b></h1>
<hr>
<table width="603" border="1" height="10" cellpadding="10">
<tr>
<td width="143">
<div align="center"><font color="#000000" size="1"><b><font size="3">学号</font></b></font></div>
</td>
<td width="108">
<div align="center"><font size="3" color="#000000"><b>姓名</b></font></div>
</td>
<td>
<div align="center"><font size="3"><b><font color="#000000">成绩</font></b></font></div>
</td>
</tr>
<%
do while not rs.eof
ID= rs ("ID")
name= rs ("name")
cj= rs ("cj")
%>
<tr>
<td height="1" width="143" align="center">
<%= ID %>
</td>
<td height="1"> <a href="mod-2.asp?name=<%=name%>"> <width="108" align="center">
<%= name %>
</td>
<td height="1"align="center">
<%= cj %>
</td>
</tr>
<% rs.movenext
loop
rs.close
set rs=nothing
conn.close
set conn=nothing
end if
%>
</table>
</center>
</BODY>
</HTML>
为什么我把conn.asp的代码放到index.asp里就好用呢? include file错了?
...全文
141 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Leeu 2005-05-15
  • 打赏
  • 举报
回复
rs.open sqlstmt,conn

我怎么觉得这里也有问题

应该是:rs.open sqlstmt,conn,1,3
anjinzhe 2005-05-12
  • 打赏
  • 举报
回复
晕啊 真就差在那了 谢了
cime63 2005-05-12
  • 打赏
  • 举报
回复
路径的问题吧?
conn.asp和index.asp是在一个文件里面吗?
newhandtoo 2005-05-12
  • 打赏
  • 举报
回复
<!-- include file="conn.asp" --> ====>> 你的include前面漏了"#"符号

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧