如何从SQL中检索表并以HTML“表"的形式显示? [英] How to retrieve table from sql and display in html "table"
本文介绍了如何从SQL中检索表并以HTML“表"的形式显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任务:我已经在html页面中使用了按钮和表控件,现在我的问题是在html表控件中显示sql表....
请帮助我,让我更新鲜
我的代码如下:
................................................... ...................................
task: i have taken a button and table control in html page now my problem is to display sql table in html table control ....
please help me iam a fresher
my code as follows:
.....................................................................................
<script type="text/javascript" language="javascript">
function getsqltable() {
var connection = new ActiveXObject("ADODB.Connection");
var connectionstring = "Data Source=;Initial Catalog=;User ID=sa;Password=;Provider=SQLOLEDB";
connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");
rs.Open("select * from sample", connection);
rs.MoveFirst
while (!rs.eof) {
var tdt = rs.fields(0);
var tdt2 = tdt + rs.fields(1);
table1.width = tdt2;
rs.movenext;
}
rs.close;
connection.close;
}
</script>
</head>
<body>
<input id="Button1" onclick="getsql();" type="button" value="button" />
<table style="width: 100%;">
<tr>
<td id="table1">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td id="table1">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</body>
</html>
推荐答案
以下方法之一:
0)您需要另一个JavaScript函数,该函数可以从返回的数据表中获取一行,然后构建/返回一个表示html表行的字符串.您需要将数据表设置为全局.
1)编写另一个接受数据行的方法,然后构建/返回一个表示html表行的字符串.
2)只需遍历数据行,并以已有的方法构建html,然后返回生成的字符串.
One of these methods:
0) You need another javascript function that can fetch a row from the returned datatable, and then build/return a string that represents the html table row. You would need to make your datatable global.
1) Write another method that accepts a datarow, and then build/return a string that represents the html table row.
2) Just iterate through the datarows and build your html in the method you already have, and return the resulting string.
先生,请给我代码,这样我就可以完成我的任务像这样的先生,我尝试了很多先生,感谢您的回复,以保护您提供给我的信息
sir plz give me the code so as i can do my task iam not understanding like this sir i tried a lot sir plz and thank u for ur kind response reguarding the information u have gave to me
这篇关于如何从SQL中检索表并以HTML“表"的形式显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文