| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4326 人关注过本帖
标题:ASP高手请教,如何从Access数据库中读取数据,显示在网站公告栏,循环读取? ...
只看楼主 加入收藏
haojibao
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2010-11-25
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:7 
ASP高手请教,如何从Access数据库中读取数据,显示在网站公告栏,循环读取?
图片附件: 游客没有浏览图片的权限,请 登录注册

数据库表:
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 数据库 公告栏 Access ASP 
2010-12-04 19:30
kevinxu0638
Rank: 2
来 自:江苏
等 级:论坛游民
帖 子:147
专家分:62
注 册:2009-10-19
收藏
得分:10 
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新闻广告</title>
<link href="../css/cbebcss.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#F4F4F4" leftmargin="0" topmargin="6" marginwidth="0" marginheight="0">
<%
Dim db,rs,strSql
    Set db=Server.CreateObject("ADODB.Connection")
    db.Open "Dsn=数据库名"                           
    Set rs=Server.CreateObject("ADODB.Recordset")
    strsql="select * from 表名 "
    rs.Open strSql,db,1
%>
<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#999999" align="center">
        <tr bgcolor="#DBDBDB">
          <td width="18%" align="center"  >标题</td>
          <td width="20%" height="18" align="center" >分类</td>
          <td width="15%" height="18" align="center" > 发布时间</td>
        </tr>
        <%
Do While Not rs.Eof                  
%>
        <tr bgcolor="#FFFFFF" onmouseover="this.bgColor = '#ebebeb'" onmouseout="this.bgColor = '#FFFFFF'">
          <td height="11" align="center"><%=rs("title")%></td>
          <td height="11" align="center"><%=rs("typestr")%></td>
          <td height="11" align="center"><%=rs("uptime")%></td>
        </tr>
   <%
rs.MoveNext
Loop
%>
</table>
</body>
</html>

[ 本帖最后由 kevinxu0638 于 2010-12-4 19:46 编辑 ]

javascript、asp学习研究中 希望高手多多指教
2010-12-04 19:36
haojibao
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2010-11-25
收藏
得分:0 
kevinxu0638您好,谢谢你的回复,但我还是没有看明白?
2010-12-04 19:48
kevinxu0638
Rank: 2
来 自:江苏
等 级:论坛游民
帖 子:147
专家分:62
注 册:2009-10-19
收藏
得分:0 
回复 3楼 haojibao
你把你的数据库名和表名写上 任何把表格里的字段换成你表里的就行了  这个不带分页的
这个是用的一个DO loop循环

javascript、asp学习研究中 希望高手多多指教
2010-12-04 19:54
kevinxu0638
Rank: 2
来 自:江苏
等 级:论坛游民
帖 子:147
专家分:62
注 册:2009-10-19
收藏
得分:0 
程序代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.>
<html xmlns="http://www.>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新闻广告</title>
<link href="../css/cbebcss.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#F4F4F4" leftmargin="0" topmargin="6" marginwidth="0" marginheight="0">
<%
Dim db,rs,strSql
    Set db=Server.CreateObject("ADODB.Connection")
    db.Open "Dsn=XX" ' XX换成你的数据库名                    
    Set rs=Server.CreateObject("ADODB.Recordset")
    strsql="select * from XX " ' XX换成你的表名
    rs.Open strSql,db,1
%>
<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#999999" align="center">
        <tr bgcolor="#DBDBDB">
          <td>标题</td>
          <td>分类</td>
          <td> 发布时间</td>' 这是表格部分你会的吧
          </tr>
<%
Rs.PageSize = 3 '数字是控制一页显示的条数
If Request("PageNo") = "" Then PageNo=1 Else PageNo = CInt(Request("PageNo"))
If PageNo < 1 Then Response.Redirect "?PageNo=1"
If PageNo > Rs.PageCount And Rs.PageCount > 0 Then Response.Redirect "?PageNo=" & Rs.PageCount
If Rs.Eof and Rs.Bof Then PageNo = 0 Else Rs.AbsOlutePage = PageNo
%>
       <%For x = 1 to Rs.PageSize
If Rs.Eof Then Exit For
%>
        <tr bgcolor="#FFFFFF" onmouseover="this.bgColor = '#ebebeb'" onmouseout="this.bgColor = '#FFFFFF'">
          <td><%=rs("title")%></td>
          <td><%=rs("typestr")%></td>
          <td><%=rs("uptime")%></td> '这边写与上面对应的字段名比如你的表里有个XX就写<%=rs("XX")%>
          </tr>
  <%rs.movenext
next%></table><table  cellspacing="0" width="508" border="0"  align="center">

                <tr><td>&nbsp;</td></tr>  
              <tr>
                <td align="center" >
           <%CurrentPage= PageNo
           showpage "?",rs.recordcount,Rs.PageSize,true,true,"" %>
           
</td>
              </tr>
            </table>
            <%
sub showpage(sfilename,totalnumber,maxperpage,ShowTotal,ShowAllPages,strUnit)
    dim n, i,strTemp,strUrl
    if totalnumber mod maxperpage=0 then
        n= totalnumber \ maxperpage
      else
        n= totalnumber \ maxperpage+1
      end if
      strTemp= "<table align='center'><form name='showpages' method='Post' action='" & sfilename & "'><tr><td>"
    if ShowTotal=true then
        strTemp=strTemp & "共 <b>" & totalnumber & "</b> " & strUnit & "&nbsp;&nbsp;"
    end if
    strUrl=(sfilename)
      if CurrentPage<2 then
            strTemp=strTemp & "首页 上一页&nbsp;"
      else
            strTemp=strTemp & "<a href='" & strUrl & "PageNo=1'>首页</a>&nbsp;"
            strTemp=strTemp & "<a href='" & strUrl & "PageNo=" & (CurrentPage-1) & "'>上一页</a>&nbsp;"
      end if

      if n-currentpage<1 then
            strTemp=strTemp & "下一页 尾页"
      else
            strTemp=strTemp & "<a href='" & strUrl & "PageNo=" & (CurrentPage+1) & "'>下一页</a>&nbsp;"
            strTemp=strTemp & "<a href='" & strUrl & "PageNo=" & n & "'>尾页</a>"
      end if
       strTemp=strTemp & "&nbsp;页次:<strong><font color=red>" & CurrentPage & "</font>/" & n & "</strong>页 "
    strTemp=strTemp & "&nbsp;<b>" & maxperpage & "</b>" & strUnit & "/页"
    if ShowAllPages=True then
        strTemp=strTemp & "&nbsp;转到:<select name='PageNo' size='1' onchange='javascript:submit()'>"  
        for i = 1 to n  
            strTemp=strTemp & "<option value='" & i & "'"
            if cint(CurrentPage)=cint(i) then strTemp=strTemp & " selected "
            strTemp=strTemp & ">第" & i & "页</option>"  
        next
        strTemp=strTemp & "</select>"
    end if
    strTemp=strTemp & "</td></tr></form></table>"
    response.write strTemp
end sub %>
</body>
</html>
这个带分页的 PS这个分页比我原来的好 呵呵 这个分页是论坛的高手教的

javascript、asp学习研究中 希望高手多多指教
2010-12-04 20:17
haojibao
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2010-11-25
收藏
得分:0 
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新闻广告</title>
<link href="../css/cbebcss.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#F4F4F4" leftmargin="0" topmargin="6" marginwidth="0" marginheight="0">
<%
以上这些内容用加在我的网站代码中吗?
2010-12-04 21:17
haojibao
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2010-11-25
收藏
得分:0 
kevinxu0638非常感谢您的回复,在指点一下!谢谢!
2010-12-04 21:18
kevinxu0638
Rank: 2
来 自:江苏
等 级:论坛游民
帖 子:147
专家分:62
注 册:2009-10-19
收藏
得分:0 
回复 6楼 haojibao
<link href="../css/cbebcss.css" rel="stylesheet" type="text/css"> 这是我自己做的页面用的css样式了你没有当然要删了
<body bgcolor="#F4F4F4" leftmargin="0" topmargin="6" marginwidth="0" marginheight="0"> 这是对body部分的一些设置了你可以直接写<body>
这位仁兄要灵活点喔
 

javascript、asp学习研究中 希望高手多多指教
2010-12-04 21:30
快速回复:ASP高手请教,如何从Access数据库中读取数据,显示在网站公告栏,循环 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023914 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved