2013-12-09 21 views
0

我目前正在使用Javascript連接到我的數據庫(我知道這不是最好的方法,但這是它完成的方式,無法更改它)在Javascript中的一個Open()記錄集函數中使用多個查詢

這是我在做什麼:

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; 
    } 


} 

}

有沒有一種方法,使成一個大的查詢,而不是打開了這一切,記錄多次關閉?

謝謝!

回答

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); 

希望這有助於任何人

相關問題