rahul002
10-29-2009, 11:13 AM
Hello All,
I want to connect to SQL Server using Javascript.
Can anyone tell me the code.
Currently i am using following code. But its giving error.
<script type="text/javascript" language="JavaScript">
function FetchRecord(){
var ConProv = new ActiveXObject("ADODB.Connection");
var ConnString ="Driver={SQL Server};Server=serverName;Database=dbname;UID=sa;PWD=pwd";
ConProv.Open(ConnString);
var RecSet = new ActiveXObject("ADODB.Recordset");
var SqlSt = "select * from tablename";
RecSet.Open(SqlSt, ConProv);
while(!RecSet.eof) //Fetches till the end of file has reached
{
document.write(RecSet(0) + "\t\t" + RecSet(2) + "\t\t" + RecSet(3) + "<br>");
RecSet.MoveNext();
}
RecSet.Close();
ConProv.Close();
}
</script>
Quick response will be appreciated.
Thanks,
Rahul
I want to connect to SQL Server using Javascript.
Can anyone tell me the code.
Currently i am using following code. But its giving error.
<script type="text/javascript" language="JavaScript">
function FetchRecord(){
var ConProv = new ActiveXObject("ADODB.Connection");
var ConnString ="Driver={SQL Server};Server=serverName;Database=dbname;UID=sa;PWD=pwd";
ConProv.Open(ConnString);
var RecSet = new ActiveXObject("ADODB.Recordset");
var SqlSt = "select * from tablename";
RecSet.Open(SqlSt, ConProv);
while(!RecSet.eof) //Fetches till the end of file has reached
{
document.write(RecSet(0) + "\t\t" + RecSet(2) + "\t\t" + RecSet(3) + "<br>");
RecSet.MoveNext();
}
RecSet.Close();
ConProv.Close();
}
</script>
Quick response will be appreciated.
Thanks,
Rahul