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

时间:2013-12-09 16:45:01

标签: javascript html oracle connection-string recordset

我目前正在使用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;
    }


}

}

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

谢谢!

1 个答案:

答案 0 :(得分:0)

在考虑之后我意识到这很简单。最好的方法是使用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);

希望这有助于任何人