sriram chv

sriram chv

  • NA
  • 35
  • 29.5k

How to get table from sql to htmltable using javascript

Aug 9 2011 2:54 AM
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>

Answers (1)