<html>
<head>
<title>表格顯示數(shù)據(jù)表記錄</title>
</head>
<body>
<h2>表格顯示數(shù)據(jù)表記錄</h2>
<hr>
<script language="JavaScript">
// 創(chuàng)建數(shù)據(jù)庫對象
var objdbConn = new ActiveXObject("ADODB.Connection");
// DSN字符串
var strdsn = "Driver={SQL Server};SERVER=127.0.0.1;UID=sa;PWD=sa;DATABASE=bbs";
// 打開數(shù)據(jù)源
objdbConn.Open(strdsn);
// 執(zhí)行SQL的數(shù)據(jù)庫查詢
var objrs = objdbConn.Execute("SELECT * FROM xxbs");
// 獲取字段數(shù)目
var fdCount = objrs.Fields.Count - 1;
// 檢查是否有記錄
if (!objrs.EOF){
document.write("<table border=1><tr>");
// 顯示數(shù)據(jù)庫的字段名稱
for (var i=0; i <= fdCount; i++)
document.write("<td><b>" + objrs.Fields(i).Name + "</b></td>");
document.write("</tr>");
// 顯示數(shù)據(jù)庫內(nèi)容
while (!objrs.EOF){
document.write("<tr>");
// 顯示每筆記錄的字段
for (i=0; i <= fdCount; i++)
document.write("<td valign='top'>" + objrs.Fields(i).Value + "</td>");
document.write("</tr>");
objrs.moveNext(); // 移到下一筆記錄
}
document.write("</table>");
}
else
document.write("數(shù)據(jù)庫內(nèi)沒有記錄!<br>");
objrs.Close(); // 關(guān)閉記錄集合
objdbConn.Close(); // 關(guān)閉數(shù)據(jù)庫鏈接
</script>
</body>
</html>
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。