在Javascript中的一个Open()记录集函数中使用多个查询
Using multiple queries in one Open() recordset function in Javascript
我目前正在使用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;
}
}
}
有没有一种方法可以将所有这些变成一个大查询,而不是多次打开和关闭记录集?
谢谢!
经过思考,我意识到它真的很简单。最好的方法是使用BEGIN
和END
语句一起运行一组查询:
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);
希望这能帮助任何
相关文章:
- 如何将参数赋予作为查询参数的参数值给定的函数
- 函数jquery.html()不提供数据属性集值
- j查询关于回调函数的术语
- javascript函数集Onclick事件
- 如何在函数带有更多postJSON查询时使用jQuery
- j查询如何在加载了 load() 函数的页面上进行 POST/AJAX,而无需刷新页面
- j查询限制文本函数
- Bluebird promisifyAll不会创建整个异步函数集
- SQLite+Javascript:在每个其他函数中执行多个查询
- php中的JavaScript函数,在点击时显示更多信息(数据库查询)
- 在Javascript中的一个Open()记录集函数中使用多个查询
- javascript onload函数范围查询
- 查询日期时间选择器未在另一个函数调用中获取日期
- 查询Mongodb时混合使用field和js函数
- 调用Javascript函数来获取sql查询的结果集,并将它们打印在html表中
- JavaScript 函数,用于使用具有多个参数的记录集查询 MS Access DB
- 使用Helper函数查询对象数组
- 从API v1.中的JavaScript函数查询融合表
- 如何将查询集从django传递到javascript函数
- Codeigniter中的表单数据通过AJAX发送到Controller函数,该函数查询数据库并返回数组