如何使用javascript将表格从sql获取到htmltable [英] how to get table from sql to htmltable using javascript

查看:96
本文介绍了如何使用javascript将表格从sql获取到htmltable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我已经执行了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>
        &nbsp;</p>
    <table style="width:100%;">
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>

推荐答案

不要重新发布您的问题人. :((

您以前的问题大约有10多个答案.如果您有任何疑问,请使用答案下方的添加评论链接对答案进行评论

只需查看您的问题历史记录

http://www.codeproject.com/script/Answers/MemberPosts.aspx? tab = questions& mid = 7994901 [ ^ ]

编辑
-------------------------------------------------- ---------
Don''t re-post your question man. :((

You got around 10+ answers for your previous questions. If you have any doubt then make a comment for answers using Add comment link below the answer

Just see your question history

http://www.codeproject.com/script/Answers/MemberPosts.aspx?tab=questions&mid=7994901[^]

EDIT
-----------------------------------------------------------
OP写道:

我的代码如下"
我的代码的错误消息":(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错误 [

Read this
Troubleshooting 800a0cc1 Errors[^]

Don''t use select * from studenttable. Use select Column1,Column2,Column3,etc., from studenttable

EDIT2
------------------------------------------------------------

OP写道:

先生,我输入了rs.Open(" 从studenttable中选择studentno,studentname,studentcourse ,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("select studentno,studentname,studentcourse from studenttable", 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来做到这一点?
One obvious question - why is your database visible on the network of the machines doing this ? Even so, why use javascript to do this ?


这篇关于如何使用javascript将表格从sql获取到htmltable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆