您好,登錄后才能下訂單哦!
這篇文章給大家介紹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怎樣循環讀取數據庫記錄就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。