JS(javascript)操作数据库->添加数据

//把数据写入数据库
function res(){
    //获取输入值(myname和mymail是两个文本框的id)
    var uname = document.getElementById("myname" ).value;
    var umail = document.getElementById("mymail" ).value;

    //数据库连接对象
    var con = new ActiveXObject("ADODB.Connection" );
    //连接字符串
    var str = "DRIVER={SQL SERVER} ;SERVER=(local);uid=sa;pwd=123456;database=xslt" ;
    //打开数据源
    con.Open(str);
    //sql语句
    var sql = "insert into xslt(name,mail) values('" + uname + "','" + umail + "')" ;
    try {
        //执行sql语句
        con.Execute(sql);
        //关闭连接
        con.Close();
        //转向成功页面
        window.location.href = "http://www.aspxcs.net/";
    }

    catch (e){
        alert(e);
    }

你可能感兴趣的:(JavaScript,sql,sql,数据库,server,database,XSLT)