网络编程
位置:首页>> 网络编程>> Asp编程>> 如何使用表格来储存数据库的记录?

如何使用表格来储存数据库的记录?

  发布时间:2010-05-16 15:14:00 

标签:表格,数据库,存储

我见到有的网站好像可以把数据库的记录读到表格里去,是这样的吗?如何做到的?

可能是这样的,因为我们确实能把数据库里的记录用表格来储存,看看下面的办法:

<html>
<head>
<TITLE>用表格储存数据 - aspxhome.com</TITLE>
</head>
<body>
<% 
myDSN="DSN=Student;uid=student;pwd=magic"
mySQL="select * from publishers where state='NY'"
showblank="&nbsp;"
shownull="-null-"
set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN
set rstemp=conntemp.execute(mySQL)
If  rstemp.eof then
   response.write "对不起,暂无匹配记录,请再检查一遍<br>"
   response.write mySQL & "<br>对不起,无法创建表格……"
   conntemp.close
   set conntemp=nothing
   response.end
end if
%>
<table border=1><tr>
<%
for each whatever in rstemp.fields%>
       <td><b><%=whatever.name%></B></TD>
<% next %>
' 把标题写到表格名称栏
</tr>
<%
DO  UNTIL rstemp.eof %>
   <tr>
   <% for each whatever in rstemp.fields
      thisfield=whatever.value
      if isnull(thisfield) then
         thisfield=shownull
' 读取全部记录
      end if
      if trim(thisfield)="" then
         thisfield=showblank
      end if%>
             <td valign=top><%=thisfield%></td>
   <% next %>
   </tr>
   <%rstemp.movenext
LOOP%>
</table>
<%
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
</body>
</html>

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com