asp輸出資料庫
① asp鏁版嵁搴撳驚鐜杈撳嚭
'鍛碉紝浣曞繀榪欎箞澶嶆潅錛屽傛灉瑕佽緭鍑轟笌鏁扮粍鐩稿叧鐨勮瘽錛屼笉瑕佸繕浜哸sp閲屾湁涓寰堝ソ鐢ㄧ殑rs.GetRows()浜嗭紝緇欎綘孌墊渶綆鍗曠殑浠g爜鍚э紝濡備笅錛歞im rs,arr,iset rs=conn.execute("select * from Navigation where ViewFlag order by Sequence asc")if not rs.eof then arr=rs.GetRows() '榪欓噷鎶婄﹀悎鏉′歡鐨勬墍鏈夎板綍閮戒繚瀛樺埌浜哸rr涓錛岃繖閲岃祴鍊煎悗鐨刟rr灝辯瓑浜庢槸涓涓浜岀淮鏁扮粍浜唀nd if
rs.closeset rs=nothing'涓婇潰浠g爜灝卞畬鎴愪簡浠庢暟鎹搴撹誨彇鏁版嵁鍒版暟緇勫彉閲忎簡錛屾帴涓嬫潵鍙瑕佽緭鍑烘暟鎹錛屼綘鍙闇瑕佸垽鏂璦rr鏄鍚︽暟緇剗f isarray(arr) then for i=0 to ubound(arr,2) '涓婇潰鏈変粊鍏勮磋繃鏁扮粍闀垮害鐢眜bound涓嬫爣鍐沖畾娌¢敊錛屾墍浠ヤ綘鍙瑕佺『瀹氱浜岀淮鐨勪笅鏍囧氨鐭ラ亾鏁扮粍闀垮害ubound(arr,2)錛屽綋鐒剁涓緇村氨鏄痷bound(arr,1)鎴栬卽bound(arr)灝辮屼簡 response.write arr(0,i) '榪欓噷灝辨槸杈撳嚭鏁扮粍item浜 response.write "<br>" '姣忚緭鍑轟竴涓鏁版嵁灝辨崲涓琛岋紝褰撶劧浣犱篃鍙浠ユ敼鎴愬埆鐨 nextelse response.write "鏆傛棤瀵艱埅"end if '鎼炲畾
② asp杈撳嚭鏁版嵁搴撳唴瀹
ASP濡備綍qu璇誨彇鏁版嵁搴擄紵
鎶婃垜瀵瑰彟涓闂棰樼殑鍥炵瓟鐨勯儴鍒嗗唴瀹硅創緇欎綘錛屽笇鏈涗綘鑳芥槑鐧姐
鍋囪句簨鍏堝緩絝嬩簡涓涓鍚嶄負鈥渢est.mdb鈥濈殑ACCESS鏁版嵁搴擄紝閲岄潰鏈変竴涓鍚嶄負鈥淎鈥濈殑琛錛岃〃A鏈変袱涓瀛楁碘渘ame鈥濆拰鈥減rice鈥,
鏈3鏉¤板綍銆傚嵆錛
name price
aaa 123
bbb 456
ccc 789
璇瘋皟璇曚笅渚嬶細(test1.asp鍙婃暟鎹搴搕est.mdb瑕佸湪鍚屼竴鐩褰曚笅錛
test1.asp
<%
'榪炴帴鏁版嵁搴
set conn=server.createobject("adodb.connection")
provider="provider=microsoft.jet.oledb.4.0;"
DBPath ="data source=" & Server.MapPath("test.mdb")
conn.Open provider & DBPath
'寤虹珛鏌ヨ
sql="select * from A"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
'鏄劇ず鏁版嵁搴撲腑鐨勬暟鎹
Response.Write "<table border='1' width='200'>"
while not rs.eof
Response.Write "<tr><td>" & rs("name") & "</td><td>" & rs("price") & "</td></tr>"
rs.movenext
wend
Response.Write "</table>"
'鍏抽棴鏁版嵁搴
rs.close
set rs=nothing
set conn=nothing
%>
③ asp資料庫循環輸出
'呵,何必這么復雜,如果要輸出與數組相關的話,不要忘了asp里有個很好用的rs.GetRows()了,給你段最簡單的代碼吧,如下:dim rs,arr,iset rs=conn.execute("select * from Navigation where ViewFlag order by Sequence asc")if not rs.eof then arr=rs.GetRows() '這里把符合條件的所有記錄都保存到了arr中,這里賦值後的arr就等於是一個二維數組了end if
rs.closeset rs=nothing'上面代碼就完成了從資料庫讀取數據到數組變數了,接下來只要輸出數據,你只需要判斷arr是否數組if isarray(arr) then for i=0 to ubound(arr,2) '上面有仁兄說過數組長度由ubound下標決定沒錯,所以你只要確定第二維的下標就知道數組長度ubound(arr,2),當然第一維就是ubound(arr,1)或者ubound(arr)就行了 response.write arr(0,i) '這里就是輸出數組item了 response.write "<br>" '每輸出一個數據就換一行,當然你也可以改成別的 nextelse response.write "暫無導航"end if '搞定