Asp读取Access数据库

Visionboy_ 2008-12-02 02:13:21
先谢过!O(∩_∩)O。。
//文件Conn.asp连接两个数据库 已测(截取部分代码)
Sub OpenConn()
On Error Resume Next
Db = "Data/data.asp" '数据库目录和名称,请使用绝对路径.
SqlString = "Now()"
ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(Db)
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr

'Dvbbs_conn 连接Dvbbs数据库

Db2 = "BBS/Data/data.asp" '数据库目录和名称,请使用绝对路径.
SqlString2 = "Now()"
ConnStr2 = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(Db2)
Set conn2 = Server.CreateObject("ADODB.Connection")
conn2.open ConnStr2
//////////////////////////////////////////////////////////
//首页 index.asp 引用 <!--#include file="conn.asp"-->
问题:如何读取显示 Db2 = "BBS/Data/data.asp" 数据库中 [Topic] 表中 Title 等字段的信息!~?
...全文
382 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
<%
set rs=server.createobject("adodb.recordset")
sqlfox="select * from Dv_Topic order by desc" 'by后面漏了一个字段
rs.open sqlfox,conn2,1,1
if rs.eof then
response.write "还没有!"
else
do while not rsfox.eof '这个错误,应该是rs而不是rsfox
%>
<tr>
<td width="100%">· <a target="_blank" href="shangjiainfo.asp?id= <%=rsfox("id")%>"> <%=left(rs("title"),21)%> </a> </td>
</tr>
<%
asjj=asjj+1
if asjj=5 then exit do
rs.movenext
loop
end if
rs.close
set rs=nothing
%>
wenhua200888 2008-12-03
  • 打赏
  • 举报
回复
改成这样就可以了

<%
set rs=server.createobject("adodb.recordset")
sqlfox="select * from Dv_Topic order by id desc"
rs.open sqlfox,conn2,1,1
if rs.eof then
response.write "还没有!"
else
do while not rs.eof
%>
<tr>
<td width="100%">· <a target="_blank" href="shangjiainfo.asp?id= <%=rs("id")%>"> <%=left(rs("title"),21)%> </a> </td>
</tr>
<%
asjj=asjj+1
if asjj=5 then exit do
rs.movenext
loop
end if
rs.close
set rs=nothing
%>
wenhua200888 2008-12-03
  • 打赏
  • 举报
回复
改成这样就可以了

<%
set rs=server.createobject("adodb.recordset")
sqlfox="select * from Dv_Topic order by desc"
rs.open sqlfox,conn2,1,1
if rs.eof then
response.write "还没有!"
else
do while not rs.eof
%>
<tr>
<td width="100%">· <a target="_blank" href="shangjiainfo.asp?id= <%=rs("id")%>"> <%=left(rs("title"),21)%> </a> </td>
</tr>
<%
asjj=asjj+1
if asjj=5 then exit do
rs.movenext
loop
end if
rs.close
set rs=nothing
%>
virgo2008 2008-12-02
  • 打赏
  • 举报
回复

sqlfox="select * from Dv_Topic order by desc"

你是对什么在排序啊?by后面的东西跑哪去了
初学者ASP-NET 2008-12-02
  • 打赏
  • 举报
回复

<%
set rs=Server.CreateObject("ADODB.Recordset")
sql="select 字段 from 数据表名"
rs.open sql,conn,1,1 '注解:其中1,1表示只读数据
%>
孤帆远影_q 2008-12-02
  • 打赏
  • 举报
回复
表名
到底是Dv_Topic还是Topic
Visionboy_ 2008-12-02
  • 打赏
  • 举报
回复
/////////////这样读取为什么出不来
<%
set rs=server.createobject("adodb.recordset")
sqlfox="select * from Dv_Topic order by desc"
rs.open sqlfox,conn2,1,1
if rs.eof then
response.write "还没有!"
else
do while not rsfox.eof
%>
<tr>
<td width="100%">·<a target="_blank" href="shangjiainfo.asp?id=<%=rsfox("id")%>"><%=left(rs("title"),21)%></a></td>
</tr>
<%
asjj=asjj+1
if asjj=5 then exit do
rs.movenext
loop
end if
rs.close
set rs=nothing
%>
tomscat 2008-12-02
  • 打赏
  • 举报
回复
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "SELECT * FROM [Topic]", conn2, 3, 1
Do While Not RS.EOF
Response.Write RS("字段名1")
Response.Write RS("字段名2")
...........................
RS.MoveNext
Loop

28,409

社区成员

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

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