|
ASP快速开发方法之数据操作(3) conn.open if Err Then err.Clear Set Conn = Nothing GBL_CHK_TempStr = GBL_CHK_TempStr & "数据库连接错误!" Response.Write GBL_CHK_TempStr Response.End End If End Sub %>
现在我们的showit.asp可以这样写:
showit.asp <!--#include file="conn.asp" --> <% sql = "Select * from cnarticle" opendatabase rs.Open sql,conn,1,1 If not Rs.eof then Do Until rs.EOF response.write("文章标题是:"& rs("cn_title")) response.write("<br>文章作者是:"& rs("cn_author")) response.write("<br>文章加入时间是:"& rs("cn_time")) response.write("<br>文章内容是:"& rs("cn_content")) response.write("<hr>") rs.MoveNext Loop else response.write ("暂时还没有文章") end if Closedatabase %>
嗯,我们又少写了一些东西,这样是最简单的吗?当然不是!还可以更简单。 使用GetRows把查询出来的数据传给一个变量,使用ubound方法取得数据记录条数。 不明白?没关系,让我们继续往下看:
再建个文件:sql.asp
sql.asp <% Class DataTable public Function SelectData(sql) If sql<>"" then opendatabase Rs.open sql,conn,1,1 If not Rs.eof then
|