问题描述
大家好,
我已经执行了html页面,我的任务是我已经执行了html页面中的按钮和表格,我的任务是当单击sqlserver中的按钮表时,必须使用javascript显示在html表中"(我写了一段代码,它没有执行请编辑我的代码,以便我可以执行)
我的代码如下"
我的代码的错误消息":(ADODB.Recordset:在集合中找不到与所请求名称或顺序相对应的项目.)
hi everybody,
i have taken a html page my task was i have taken a button and table in html page ,my task is "when clicked on button table in sqlserver must display in html table using javascript("i have written a piece of code its not executing please edit my code so that i can execute")
"my code is as follows"
"errormessage of my code":(ADODB.Recordset: Item cannot be found in the collection corresponding to the requested name or ordinal.)
<script language="javascript" type="text/javascript">
function getsqltable()
{
var strtable;
var connection = new ActiveXObject("ADODB.Connection");
var connectionstring = "Persist Security Info=False;Data Source=xxxxxx;Initial Catalog=xxxx;User ID=sa;Password=xxxx;Provider=SQLOLEDB";
connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");
rs.Open("select * from studenttable", connection);
rs.MoveFirst
strtable='<table cellpadding=0 cellspacing=0 width=75%>';
while (!rs.eof)
{
strtable+='<tr>';
strtable += '<td>' + rs.fields(0) + '</td>' + '<td>' + rs.fields(1) + '</td>' + '<td>' + rs.fields(2) + '</td>' + '<td>' + rs.fields(3) + '</td>'
strtable+='</tr>';
rs.movenext;
}
strtable+='</table>';
rs.close;
connection.close;
document.getElementById('htmltable').innerHTML=strtable;
}
</script>
<input type="button" onclick="getsqltable();" value="Click Me" />
<div id="htmltable">
</div>
<p>
</p>
<table style="width:100%;">
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
推荐答案
我的代码如下"
我的代码的错误消息":(ADODB.Recordset:在集合中找不到与所请求名称或顺序相对应的项目.)
"my code is as follows"
"errormessage of my code":(ADODB.Recordset: Item cannot be found in the collection corresponding to the requested name or ordinal.)
阅读此内容
排除800a0cc1错误 [ ^ ]
不要使用select * from studenttable
.使用select Column1,Column2,Column3,etc., from studenttable
EDIT2
-------------------------------------------------- ----------
Read this
Troubleshooting 800a0cc1 Errors[^]
Don''t use select * from studenttable
. Use select Column1,Column2,Column3,etc., from studenttable
EDIT2
------------------------------------------------------------
先生,我输入了rs.Open(" ,connection);再次在下一行给出给定错误sir,例如strtable + =''< td>''+ rs.fields (0) +''</td>''+``< td>''+ rs.fields (1) +''</td>''+''< td>''+ rs.fields (2) +''</td>''+``< td>''+ rs.fields (3) +''</td> ;''ADODB.Recordset:在集合中找不到与所请求名称或顺序相对应的项目.
sir i entered rs.Open("", connection);again its giving error sir in the following line like this strtable += ''<td>'' + rs.fields(0) + ''</td>'' + ''<td>'' + rs.fields(1) + ''</td>'' + ''<td>'' + rs.fields(2) + ''</td>'' + ''<td>'' + rs.fields(3) + ''</td>'' ADODB.Recordset: Item cannot be found in the collection corresponding to the requested name or ordinal.
在查询中,您只选择查询中的 3列.但是在您的代码中,您尝试获取 4列.这就是问题所在.因此,请在查询中选择第四列.
In your query, you are selecting only 3 columns in your query. But in your code you are trying to get 4 columns. That''s the issue. So select the 4th column in your query.
这篇关于如何使用javascript将表格从sql获取到htmltable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!