关于在一个网页中了用两个数据库的问题

zerodawn77 2002-05-07 09:38:52
我做了一个网页,里面分了两个模块:新闻和文件,用<!--#include file=name1.asp>和<!--#include file=name2.asp>分别调用,连接两个不同的数据库,但问题出现了,只能显示一个模块,先后换一下就显示另外一个,我估计是不是冲突的问题,谁能帮我解决一下。
...全文
55 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
zerodawn77 2002-05-07
  • 打赏
  • 举报
回复
那怎么补救呢
popcode 2002-05-07
  • 打赏
  • 举报
回复
Pasp (50)、 其他的没分?????
zerodawn77 2002-05-07
  • 打赏
  • 举报
回复
怎么就给了一个人那,真是不好意思。那怎么补救呢
zerodawn77 2002-05-07
  • 打赏
  • 举报
回复
不知道对不对,大家注意接收了
popcode 2002-05-07
  • 打赏
  • 举报
回复
点帖子后面的管理
zerodawn77 2002-05-07
  • 打赏
  • 举报
回复
好了,我怎么给你们分呢?告诉我,我觉得你们帮了我很大的忙
popcode 2002-05-07
  • 打赏
  • 举报
回复
表名和字段名、字段类型不要改动,把那两个表放在同一个数据库中,用connstr2="DBQ="+server.mappath("数据库路径")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
连接
zerodawn77 2002-05-07
  • 打赏
  • 举报
回复
别说,上面的朋友对我倒是个提醒,我可以把我的两个库合成一个库,用两个不同的表吗,你能不能写一段具体的代码给我?
zerodawn77 2002-05-07
  • 打赏
  • 举报
回复
是两个不同的库
zerodawn77 2002-05-07
  • 打赏
  • 举报
回复
这是首页中连接两个模块的代码:
<tr>
<td height="9" width="347" valign="top" rowspan="2"><!--#include file="demo.asp"--></td>
</tr>
<tr>
<td height="185" width="159" valign="top" rowspan="2"><!--#include file="news.asp"--></td>
</tr>
下面的是news.asp的代码:
<html>
<head>
<title>淳安县府内部网</title>
<script language="javascript">
function view(id,path)
{ window.open("open.asp?id="+id+"&ppath="+path,"","resizable=yes,scrollbars2=yes,status=yes,toolbar=yes,menubar=yes,location=yes");
}
</script>
<meta http-equiv="Content-Type" content="text/html; chars2et=gb2312">

<style type="text/css">
<!--
body { font-family: "宋体"; font-size: 9pt}
p { }
table { font-family: "宋体"; font-size: 9pt}
td { font-family: "宋体"; font-size: 9pt; line-height: 14pt; letter-spacing: 0pt}
a:link { font-family: "宋体"; color: #000000;text-decoration: none}
a:hover { font-family: "宋体"; color: #008080}
a:visited { font-family: "宋体"; color: #000000;text-decoration: none}
-->
</style>
</head>
<!--#include file="conn4.asp"-->
<%
const MaxPerPage2=5
dim totalPut2
dim CurrentPage2
dim TotalPages2
if not isempty(request("page")) then
CurrentPage2=cint(request("page"))
else
CurrentPage2=1
end if
%>

<body topmargin="0" leftmargin="0">

<table border="0" width="289" height="212" cellpadding="0" cellspacing="0">
<tr>
<td height="212" width="783" valign="top">
  
<p> 
<table border="0" width="318" height="21" cellpadding="2" style="text-indent: 0; border-top: 2 dotted #008080; border-bottom: 2 dotted #008080">
<%dim sql2
dim rs2
sql2="select * from news order by new_date desc"
Set rs2= Server.CreateObject("ADODB.Recordset")
rs2.open sql2,conn2,1,1
if rs2.eof and rs2.bof then
response.write "<p align='center'> 还 没 有 任 何 网 友 留 言 信 息</p>"
else
totalPut2=rs2.recordcount
totalPut2=rs2.recordcount
if CurrentPage2<1 then
CurrentPage2=1
end if
if (CurrentPage2-1)*MaxPerPage2>totalPut2 then
if (totalPut2 mod MaxPerPage2)=0 then
CurrentPage2= totalPut2 \ MaxPerPage2
else
CurrentPage2= totalPut2 \ MaxPerPage2 + 1
end if

end if
if CurrentPage2=1 then
showContent
showpage totalPut2,MaxPerPage2,"news.asp"
else
if (CurrentPage2-1)*MaxPerPage2<totalPut2 then
rs2.move (CurrentPage2-1)*MaxPerPage2
dim bookmark2
bookmark2=rs2.bookmark2
showContent
showpage totalPut2,MaxPerPage2,"news.asp"
else
CurrentPage2=1
showContent
showpage totalPut2,MaxPerPage2,"news.asp"
end if
end if
' rs2.close
end if
' set rs2=nothing
' conn2.close
' set conn2=nothing
sub showContent
dim i
i=0%>
<%do while not rs2.eof%>
<tr>
<td width="18" height="15">☆</td>
<td width="195" height="15"><a href="javascript:view(<%=rs2("id")%>)"><%=rs2("new_zhuti")%></a></td>
<td width="83" height="15"><%=rs2("new_date")%> </td>
</tr>
<% i=i+1
if i>=MaxPerPage2 then exit do
rs2.movenext
loop
%>
<%
end sub

%>

</table>
 
<p>                      
</td>
</tr>

</table>
</body>
</html>
下面是conn4.asp的代码:
<%
dim conn2
dim connstr2

on error resume next
connstr2="DBQ="+server.mappath("database.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn2=server.createobject("ADODB.CONNECTION")
conn2.open connstr2
%>

文件的代码和这个基本差不多,就是rs,conn什么的不一样
代码太乱,见笑了,还希望大家多多帮忙,等用。
sunliu0811 2002-05-07
  • 打赏
  • 举报
回复
连接的是两个数据库,还是一个库中的两个表。

要是表的话,其实很好解决。

<!--#include file="conn.asp" -->
<%
set rst=server.createobject("adodb.recordset")
sqltext5="select top 1 * from Product where P_tuijian='yes' order by regtime desc"
rst.open sqltext5,conn,1,1

set rs=server.createobject("adodb.recordset")
sqltext="select top 3 * from Product order by regtime desc"
rs.open sqltext,conn,1,1
%>
显示完一次查询的结果后,就关一次。

<% While Not rs.EOF %>
<%=rs("id")%>
<%
rs.MoveNext
Wend
rs.close
%>
<% While Not rst.EOF %>
<%=rst("id")%>
<%
rst.MoveNext
Wend
rst.close
%>
saucer 2002-05-07
  • 打赏
  • 举报
回复
你是怎么连数据库的?把编码贴出来?
zerodawn77 2002-05-07
  • 打赏
  • 举报
回复
我把重名的都该了,可还是不行
zerodawn77 2002-05-07
  • 打赏
  • 举报
回复
他提示:<%do while not rs2.eof%>这里有错误,因为是两个连接库,原来是rs,我换成了rs2,可我也不知道怎么该,帮帮忙
Pasp 2002-05-07
  • 打赏
  • 举报
回复
1。你的这3个文件中是否加了 on error resume next 将它去掉,就显示错误了
2.估计是你的两个连接数据库文件参数相同,改为不同即可
例如:两个文件中都是 conn rs

28,409

社区成员

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

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