中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 教育认证 > 其他认证
asp 向 sql server 2k 要数据
作者:未知 时间:2005-09-13 23:54 出处:Blog.ChinaUnix.net 责编:chinaitpower
              摘要:asp 向 sql server 2k 要数据

本地服务器数据库 testdb

表 title1

name       urlname              id        
---------- -------------------- ---------- 
a         ./x.asp          1         
b       ./a.asp          2         
c       ./j.asp           3         
d       ./p.asp           4         
e       ./n.asp           5         
f       ./k.asp           6         g       ./lx.asp           7   

表 title2

name                                               urlname                                            id         id2       
-------------------------------------------------- -------------------------------------------------- ---------- ---------- 
b1                                               ./g.asp                                         2          21        
b2                                               ./h.asp                                         2          22        
b3                                              ./y.asp                                         2          23        
b4                                              ./l.asp                                         2          24        
c1                                             ./h.asp                                        3          31        
c2                                              ./s.asp                                         3          32        
c3                                       ./x.asp                                        3          33        
d1                                            ./z.asp                                       4          41        
d2                                         ./k.asp                                       4          42        
d3                                           ./g.asp                                       4          43        
d4                                         ./c.asp                                       4          44        
d5                                        ./x.asp                                  4          45                    

asp  连接文件

<%
set cn = Server.CreateObject("ADODB.Connection")
cnstr="Provider=SQLOLEDB.1;Data Source=(local);User ID=sa;Password=;Database=testdb;"
on error resume next
cn.open cnstr
if err.number <> 0 then
 response.redirect("err.asp?xx=不能连接数据库,可能是WEB数据库服务器没有启动")
end if
%>

asp 数据需求文件

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<!--#include file="conn.asp"-->
<% 
set rs=server.CreateObject("adodb.recordset")
rs.open"select * from title1",cn,1,1
%>
<style type="text/css">
<!--
body {
 margin-left: 0px;
 margin-top: 0px;
 margin-right: 0px;
 margin-bottom: 0px;
}
-->
</style>
</head>

<body>
<table width="100%" border="0">
  <tr>
    <th align="left" bgcolor="#666699" scope="col">
 
 <%
      do while not rs.eof 
     %>
  <a href="<%=rs("urlname")%>" target="_self"><%= rs("name") %></a><br>
   
  <% idStr = rs("id")
  set rs1=server.CreateObject("adodb.recordset")
  rs1.open "SELECT * FROM title2 WHERE id = '"&idStr&"'",cn,1,1
  if rs1<>NaN then
 %>
   <%
      do while not rs1.eof 
      %>
   <a href="<%=rs1("urlname")%>" target="_self"><%= rs1("name") %></a><br>
 
   <%
   rs1.movenext
   loop
  %>
   <%
   rs1.close
  %>
  <% end if %>
 
   
  <%
  rs.movenext
  loop
 %>
 <% rs.close %>
 <% cn.close %> </th>
  </tr>
</table>
</body>
</html>

结果


b
b1 
b2
b3
b4 
c
c1 
c2 
c3 

d1 
d2 
d3 
d4 
d5 

f
g

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有