Client.Html页面源码如下:
<html>
<head>
<title>get data from database at client</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<style type="text/css">
<!--
body{font-family:Times New Roman;font-size:9pt;}
table{font-family:Times New Roman;font-size:9pt;}
button{color:blue;}
//-->
</style>
<script language="Javascript">
<!--
function connectDB()
{
try{
var count=0;
var conn=new ActiveXObject("ADODB.Connection");
var rs=new ActiveXObject("ADODB.Recordset");
var connectString="provider=sqloledb.1;user id=sa;password=;data source=coolbug;Initial Catalog=pubs";
var selectString="select top 5 * from sales";
var tableString="";
conn.open(connectString);
rs=conn.execute(selectString);
while(!rs.EOF)
{
if(count++==0)
{
tableString+="<table border='1'><tr><td>"+rs(0).name+"</td>";
tableString+="<td>"+rs(1).name+"</td></tr>";
}
tableString+="<tr><td>"+rs(0).value+"</td>";
tableString+="<td>"+rs(1).value+"</td></tr>";
rs.moveNext();
}
tableString+="</table><br>";
document.getElementById("dataArea").innerHTML=tableString;
rs.close();
conn.close;
}
catch(e)
{
document.write(e.toString());
}
}
//-->
</script>
</head>
<body>
<div id="dataArea"></div>
<button onclick="connectDB();">retrieve data</button>
</body>
</html>
如果要访问别的数据库,就请修改,连接方式。
希望此次抛砖,能引玉。
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://coolbug.cnblogs.com/images/cnblogs_com/coolbug/ClientHtml.jpg)
如果要访问别的数据库,就请修改,连接方式。
希望此次抛砖,能引玉。