网络编程
位置:首页>> 网络编程>> Asp编程>> 如何把数据库的记录输出到表格去?

如何把数据库的记录输出到表格去?

  发布时间:2009-11-06 13:37:00 

标签:表格,数据库

我看见朋友可以把数据库的记录输出到页面表格上去,觉得很有用。这是怎么做的啊?

见下:

dbtable.asp

<html>
<head>
<TITLE>精彩春风之数据库记录到表格</TITLE>
</head>
<body bgcolor="#FFFFFF">
<% 
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>
<% 'Put Headings On The Table of Field Names
for each whatever in rstemp.fields%>
      <td><b><%=whatever.name%></B></TD>
<% next %>
</tr>
<% ' Now lets grab all the records
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