ASP怎样循环读取数据库记录

这篇文章给大家介绍ASP怎样循环读取数据库记录,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%Session.CodePage = 936%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" >
<meta  name="viewport" content="width=device-width, initial-scale=1.0, 
     minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" >
<title>Scale3DC2018Read</title>
</head>
<body>
<%
	Set conn= Server.CreateObject("ADODB.Connection") 
	connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=
	      "&Server.MapPath("\database\Scale3DCIP.mdb") 
	conn.Open connstr 
	
	Set rs = Server.CreateObject ("ADODB.Recordset") 
	sql = "Select * from custom order by id desc" 
	rs.Open sql,conn,1,1 
	
	do while not rs.eof  
%>
    <table border=1>
	<tr>
	<td><%=rs("keyid")%></td>
	<td><%=rs("IPAddress")%></td>
	<td><%=rs("Area")%></td>
	<td><%=rs("LoginTime")%></td>
	</tr>
	<%
	    rs.movenext
	 loop
	 
	 rs.close()
	 set rs = nothing
	 
	 conn.close()
	 set conn = nothing
	%>
	</table>
</body>

写入数据库

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%Session.CodePage=936%> 
<!--#include file="web\\global.inc"-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" >
<!--meta http-equiv="Content-Type" content="text/html; charset=utf-8" /--> 
<meta  name="viewport" content="width=device-width, initial-scale=1.0,
     minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" >
<title>Scale3DC2018</title>
</head>
<body>
    <%
	     dim keyid
	     keyid = request.QueryString("keyid")
		 if IsEmpty(keyid) then
		    Response.End()
		 end if
	%>
	<%'创建连接对象
        set dbconnection=Server.CREATEOBJECT("ADODB.CONNECTION")
        DBPath =Server.MapPath("database/Scale3DCIP.mdb")
        dbconnection.Open  "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
	%>
	IP 地址
	<%
        dim ipStr	  
	        ipStr = getip()
      'Response.Redirect("http://api.map.baidu.com/location/ip?ip=
               "+getip()+"&ak=v6j7koi0ywtlK1RxZR47KSvkmmSzqIdn&coor=bd09ll")
	%>

	<%'创建记录对象
         Set rs =Server.CreateObject("ADODB.Recordset")
		 '打开记录表
		 dim stime
		 stime = Now()
		 rs.open "select * from Custom where IPAddress='"&ipStr&"'",dbconnection,1,3
		 if  rs.eof then
		    rs.close()
		    rs.Open "insert into Custom(KeyID,IPAddress,Area,loginTime)values 
		           ('"&keyid&"','"&ipStr&"','','"&stime&"')", dbconnection,1, 3
		 else
		    rs.close()
		    rs.Open "update Custom set loginTime ='"&stime&"' where KeyID =
		         '"&ipStr&"'", dbconnection,adOpenDynamic, 3
		 end if
	%>
	<%
	    'rs.close 无返回不需要此句
        set rs=nothing
        dbconnection.close
        set dbconnection=nothing
	%>
</body>

%后面最好不要加注释,注释加到其他行

关于ASP怎样循环读取数据库记录就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:niceseo99@gmail.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

评论

有免费节点资源,我们会通知你!加入纸飞机订阅群

×
天气预报查看日历分享网页手机扫码留言评论电报频道链接