Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.)

XML
<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>
Posted

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 wrote:
"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.)
Read this
Troubleshooting 800a0cc1 Errors[^]

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

EDIT2
------------------------------------------------------------
OP wrote:
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.

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.
 
Share this answer
 
v5
Comments
sriram from Hyderabad 9-Aug-11 2:59am    
sir iam getting error please edit my code sir as it executes find where is the problem in code
thanks in advance
thatraja 9-Aug-11 3:01am    
Check my updated answer
sriram from Hyderabad 9-Aug-11 3:16am    
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.
sriram from Hyderabad 9-Aug-11 3:19am    
thatraja sir please help me iam not able to execute it
thatraja 9-Aug-11 3:52am    
Check my updated answer
One obvious question - why is your database visible on the network of the machines doing this ? Even so, why use javascript to do this ?
 
Share this answer
 
Comments
sriram from Hyderabad 9-Aug-11 3:18am    
sir iam a fresher its my task sir i have to do like that only please help me sir see my code and above comments also
sriram from Hyderabad 9-Aug-11 3:18am    
my database is sqlserver

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900