开发者

Problem in Inserting record to Sql Server 2008 by Javascript

I am trying to insert some record into my Sql Server 2008 data base using javascript. But not happening.My code

try
        {

            var ConProv = new ActiveXObject("ADODB.Connection");             
            var ConnString ="Provider=SQLOLEDB;Data Source=SerevrName;Integrated Security=SSPI;Initial Catalog=text;User ID=xxx;Password=xxxx;";
            ConProv.Open(ConnString);
            var RecSet = new ActiveXObject("ADODB.Recordset");              
            var SqlSt = "insert into tbl_test(Col1,Col2) Values('Val1','Val2')";

            RecSet.ExecQuery(SqlSt, ConProv);
        }
        catch(err)
        {
          txt="Error description: " + err.description;    
          aler开发者_Go百科t(txt);
        }

Error Message: Object does not suport this method or property..

What is that I am missing...

N.B. I know it is not a good approach of acessing DB but I am experimenting this an learning.


Search for ADODB and OLEDB instead of javascript. Try:

try {
  var ConProv = new ActiveXObject("ADODB.Connection");             
  var ConnString = "Provider=SQLOLEDB;Data Source=SerevrName;Integrated Security=SSPI;Initial Catalog=text;User ID=xxx;Password=xxxx;";
  ConProv.Open(ConnString);
  var SqlSt = "insert into tbl_test(Col1,Col2) Values('Val1','Val2')";
  var RecSet = ConProv.Execute(SqlSt);
  ConProv.Close();
}
catch(e) {
  alert("Error description: " + e.description);
}

To have more control over parameters for SQL-commands, is more flexible to use ADODB.Command and Execute() method of ADODB.Command

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜