<html> <body> <h2>表格显示数据表记录</h2> <hr> <script language="JavaScript"> // 创建数据库对象 var objdbConn = new ActiveXObject("ADODB.Connection"); // DSN字符串 var strdsn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=INFORMFLAT;Data Source=BARCODE"; // 打开数据源 objdbConn.Open(strdsn); // 执行SQL的数据库查询 var objrs = objdbConn.Execute("SELECT VPosition,Item_Sequence,Item_Code FROM D_Manufacture_Current where VPosition < 5"); // 获取字段数目 var fdCount = objrs.Fields.Count - 1; // 检查是否有记录 if (!objrs.EOF){ document.write("<table border=1><tr>"); // 显示数据库的字段名称 for (var i=0; i <= fdCount; i++) document.write("<td><b>" + objrs.Fields(i).Name + "</b></td>"); document.write("</tr>"); // 显示数据库内容 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("数据库内没有记录!<br>"); objrs.Close(); // 关闭记录集合 objdbConn.Close(); // 关闭数据库链接 </script> </body> </html>
rsTopTen = new ActiveXObject("ADODB.Recordset"); ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=C:\\TopTen\\TopTen.mdb"; strSQL = "SELECT TopTenName, TopTenCount FROM TopTen ORDER BY TopTenCount DESC"; rsTopTen.Open(strSQL, ConnectionString, 3,1,1);// Set variable var nCounter nCounter = 0;// Loop through the Recordset while(!rsTopTen.EOF) { var nCount, strCount, strFormated // Iterate the counter nCounter++;
// Load variables from the Recordset strName = rsTopTen.Fields.Item(0).Value; nCount = rsTopTen.Fields.Item(1).Value; // Go to the next Record rsTopTen.MoveNext();};
// Close the Recordset rsTopTen.Close();
rsTopTen = new ActiveXObject("ADODB.Recordset");// Build the connection string// ConnectionString Format below: //ConnectionString = "DRIVER=SQL Server;SERVER=MySQLServer;CATALOG=MyDatabase;UID=USERID;PWD=Password"; // // for SQL 7.0: ConnectionString = "DRIVER=SQL Server;SERVER=TopTen;CATALOG=TopTen;UID=TopTen;PWD=TopTen"; // // Build a SQL statement strSQL = "SELECT TopTenName, TopTenCount FROM TopTen ORDER BY TopTenCount DESC";// Open the recordset rsTopTen.Open(strSQL, ConnectionString, 3,1,1);
var ConnectionString // Create the Recordset Object rsTopTen = new ActiveXObject("ADODB.Recordset");// Build the connection string // // ConnectionString Format below: //ConnectionString = "DRIVER=SQL Server;SERVER=MySQLServer;CATALOG=MyDatabase;UID=USERID;PWD=Password"; // // for SQL 7.0: //ConnectionString = "DRIVER=SQL Server;SERVER=TopTen;CATALOG=TopTen;UID=TopTen;PWD=TopTen"; // // for Access Database (on Server): //ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\\\demwwwdev01\\develop\\im\\security\\TopTen.mdb"; // // for Access Database (on local drive): ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=C:\\TopTen\\TopTen.mdb";// Build a SQL statement strSQL = "SELECT TopTenName, TopTenCount FROM TopTen ORDER BY TopTenCount DESC";// Open the recordset rsTopTen.Open(strSQL, ConnectionString, 3,1,1);// Set variable var nCounter nCounter = 0;// Loop through the Recordset while(!rsTopTen.EOF) { .... }
<body>
<h2>表格显示数据表记录</h2>
<hr>
<script language="JavaScript">
// 创建数据库对象
var objdbConn = new ActiveXObject("ADODB.Connection");
// DSN字符串
var strdsn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=INFORMFLAT;Data Source=BARCODE";
// 打开数据源
objdbConn.Open(strdsn);
// 执行SQL的数据库查询
var objrs = objdbConn.Execute("SELECT VPosition,Item_Sequence,Item_Code FROM D_Manufacture_Current where VPosition < 5");
// 获取字段数目
var fdCount = objrs.Fields.Count - 1;
// 检查是否有记录
if (!objrs.EOF){
document.write("<table border=1><tr>");
// 显示数据库的字段名称
for (var i=0; i <= fdCount; i++)
document.write("<td><b>" + objrs.Fields(i).Name + "</b></td>");
document.write("</tr>");
// 显示数据库内容
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("数据库内没有记录!<br>");
objrs.Close(); // 关闭记录集合
objdbConn.Close(); // 关闭数据库链接
</script>
</body>
</html>
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=C:\\TopTen\\TopTen.mdb";
strSQL = "SELECT TopTenName, TopTenCount FROM TopTen ORDER BY TopTenCount DESC";
rsTopTen.Open(strSQL, ConnectionString, 3,1,1);// Set variable
var nCounter
nCounter = 0;// Loop through the Recordset
while(!rsTopTen.EOF)
{ var nCount, strCount, strFormated // Iterate the counter
nCounter++;
// Load variables from the Recordset
strName = rsTopTen.Fields.Item(0).Value;
nCount = rsTopTen.Fields.Item(1).Value; // Go to the next Record
rsTopTen.MoveNext();};
// Close the Recordset
rsTopTen.Close();
//ConnectionString = "DRIVER=SQL Server;SERVER=MySQLServer;CATALOG=MyDatabase;UID=USERID;PWD=Password";
//
// for SQL 7.0:
ConnectionString = "DRIVER=SQL Server;SERVER=TopTen;CATALOG=TopTen;UID=TopTen;PWD=TopTen";
//
// Build a SQL statement
strSQL = "SELECT TopTenName, TopTenCount FROM TopTen ORDER BY TopTenCount DESC";// Open the recordset
rsTopTen.Open(strSQL, ConnectionString, 3,1,1);
// Create the Recordset Object
rsTopTen = new ActiveXObject("ADODB.Recordset");// Build the connection string
//
// ConnectionString Format below:
//ConnectionString = "DRIVER=SQL Server;SERVER=MySQLServer;CATALOG=MyDatabase;UID=USERID;PWD=Password";
//
// for SQL 7.0:
//ConnectionString = "DRIVER=SQL Server;SERVER=TopTen;CATALOG=TopTen;UID=TopTen;PWD=TopTen";
//
// for Access Database (on Server):
//ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\\\demwwwdev01\\develop\\im\\security\\TopTen.mdb";
//
// for Access Database (on local drive):
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=C:\\TopTen\\TopTen.mdb";// Build a SQL statement
strSQL = "SELECT TopTenName, TopTenCount FROM TopTen ORDER BY TopTenCount DESC";// Open the recordset
rsTopTen.Open(strSQL, ConnectionString, 3,1,1);// Set variable
var nCounter
nCounter = 0;// Loop through the Recordset
while(!rsTopTen.EOF)
{
....
}