在Javascript中的一个Open()记录集函数中使用多个查询

Using multiple queries in one Open() recordset function in Javascript

本文关键字:集函数 查询 记录 Open Javascript 一个      更新时间:2024-05-11

我目前正在使用Javascript连接到我的数据库(我知道这不是最好的方法,但这是它的完成方式,我无法更改它)

这就是我正在做的:

function changeCode(textfield1, textfield2, textfield3){
if(emptyFields(textfield1, textfield1, textfield1) == false){
var connection = new ActiveXObject("ADODB.Connection") ;
var connectionstring = "DSN=dsn_prod;UID=usuid;PWD=usuid";
connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");
var code= new String();
var client= new String();
var post= new String();
code= document.getElementById(textfield1).value;
client = document.getElementById(textfield2).value;
post= document.getElementById(textfield3).value;    
var r=confirm("Are you sure you wish to change code?");
if(r==true){
    rs.Open("update agen set c_it ="+code+" where n_client = "+client+" and c_post_client='"+post+"'",connection);
    rs.close;
    rs.Open("update clie set c_it="+code+" where n_client = "+client+" and c_post_client='"+post+"'",connection);
    rs.close;
    rs.Open("update ncli set c_it="+code+" where n_client= "+client+" and c_post_client='"+post+"'",connection);
    rs.close;
    rs.Open("update foli set c_it="+code+" where c_it <> "+code+" and n_client = "+client+" and c_post_client='"+post+"'",connection);
    rs.close;
    connection.close;
    }

}

}

有没有一种方法可以将所有这些变成一个大查询,而不是多次打开和关闭记录集?

谢谢!

经过思考,我意识到它真的很简单。最好的方法是使用BEGINEND语句一起运行一组查询:

rs.Open("BEGIN update agen set c_it ="+code+" where n_client = "+client+" and c_post_client='"+post+"'; update clie set c_it="+code+" where n_client = "+client+" and c_post_client='"+post+"'; update ncli set c_it="+code+" where n_client= "+client+" and c_post_client='"+post+"'; update foli set c_it="+code+" where c_it <> "+code+" and n_client = "+client+" and c_post_client='"+post+"';END;",connection);

希望这能帮助任何