使用odc文档
使用一个odc文档可以很轻松在ie浏览器中连接到sql server数据库的表,odc文档示例如下:
<html>
<head>
<meta http-equiv=content-type content=”text/x-ms-odc; charset=utf-8″>
<meta name=progid content=odc.table>
<meta name=sourcetype content=oledb>
<meta name=catalog content=k0712>
<meta name=schema content=dbo>
<meta name=table content=”t_material”>
<xml id=docprops></xml><xml id=msodc><odc:officedataconnection
xmlns:odc=”urn:schemas-microsoft-com:office:odc”
xmlns=”http://www.w3.org/tr/rec-html40″>
<odc:connection odc:type=”oledb”>
<odc:connectionstring>provider=sqloledb.1;integrated security=sspi;persist security info=true;data source=develop;use procedure for prepare=1;auto translate=true;packet size=4096;workstation id=develop;use encryption for data=false;tag with column collation when possible=false;initial catalog=k0712</odc:connectionstring>
<odc:commandtype>table</odc:commandtype>
<odc:commandtext>"k0712"."dbo"."icinventory"</odc:commandtext>
</odc:connection>
</odc:officedataconnection>
</xml>
<style>
<!–
.odcdatasource
{
behavior: url(dataconn.htc);
}
–>
</style>
</head>
<body onload=init() scroll=no leftmargin=0 topmargin=0 rightmargin=0 style=border: 0px>
<table style=border: solid 1px threedface; height: 100%; width: 100% cellpadding=0 cellspacing=0 width=100%>
<tr>
<td id=tdname style=font-family:arial; font-size:medium; padding: 3px; background-color: threedface>
</td>
<td id=tdtabledropdown style=padding: 3px; background-color: threedface; vertical-align: top; padding-bottom: 3px>
</td>
</tr>
<tr>
<td id=tddesc colspan=2 style=border-bottom: 1px threedshadow solid; font-family: arial; font-size: 1pt; padding: 2px; background-color: threedface>
</td>
</tr>
<tr>
<td colspan=2 style=height: 100%; padding-bottom: 4px; border-top: 1px threedhighlight solid;>
<div id=pt style=height: 100% class=odcdatasource></div>
</td>
</tr>
</table>
<script language=javascript>
function init() {
var sname, sdescription;
var i, j;
try {
sname = unescape(location.href)
i = sname.lastindexof(“.”)
if (i>=0) { sname = sname.substring(1, i); }
i = sname.lastindexof(“/”)
if (i>=0) { sname = sname.substring(i+1, sname.length); }
document.title = sname;
document.getelementbyid(“tdname”).innertext = sname;
sdescription = document.getelementbyid(“docprops”).innerhtml;
i = sdescription.indexof(“escription>”)
if (i>=0) { j = sdescription.indexof(“escription>”, i + 11); }
if (i>=0 && j >= 0) {
j = sdescription.lastindexof(“</”, j);
if (j>=0) {
sdescription = sdescription.substring(i+11, j);
if (sdescription != “”) {
document.getelementbyid(“tddesc”).style.fontsize=”x-small”;
document.getelementbyid(“tddesc”).innerhtml = sdescription;
}
}
}
}
catch(e) {
}
}
</script>
</body>
</html>
这样,可以很方便的在web页面上显示数据表了j
会web编程的都知道其实是一个html文本,采用javascript来初始化窗口布局,加粗的部分是数据连接的关键部分,如下所示:
<odc:connectionstring>provider=sqloledb.1;integrated security=sspi;persist security info=true;data source=develop;use procedure for prepare=1;auto translate=true;packet size=4096;workstation id=develop;use encryption for data=false;tag with column collation when possible=false;initial catalog=k0712</odc:connectionstring>
<odc:commandtype>table</odc:commandtype>
<odc:commandtext>"k0712"."dbo"."icinventory"</odc:commandtext>
其中,odc:connectionstring是数据库连接串,使用和ado一样的格式,不用多说了吧j;odc:commandtype是查询类型,table是表查询,sql是标准sql语句查询;odc:commandtext是查询命令文本,如果是table类型的,就只要写出表名称就可以了,如master.dbo.sysobjects,如果是sql类型的话,就是一般的sql语句,如“select t0.*from icstockbill t0 inner join icstockbillentry t1 on t0.fstockbillid=t1.fstockbillid order by t0.fstockbillid”