0

我正在尝试使用 javascript 检查记录是否存在(我知道这不是最安全的方法),但所有这些都是供内部使用的,安全不是问题。

于是我打开了一个记录集,

rs.Open("SELECT * FROM clie Where N_CLIENT =" + textbox1+ " AND C_POST_CLIENT = '" + textbox2+ "'",connection)

textbox1并且textbox2是我正在查看 clie 表的值,但首先我需要检查记录是否存在。我尝试将其分配rs.Open给一个变量,然后将其与某些东西进行比较,但它不起作用

我尝试使用 aRecordCount但我一直得到-1。我读到它不是为此而设计的,它不应该用于查找记录,因此必须有另一种方法来做到这一点。

更新_

这是我正在处理的整个功能

function RecordExists(textfield1, textfield2)
{
var connection = new ActiveXObject("ADODB.Connection") ;
    var connectionstring = "UID=admin;PWD=password";
    connection.Open(connectionstring);
    var rs = new ActiveXObject("ADODB.Recordset");
    var textbox1= new String();
    var textbox2=new String();
    textbox1= document.getElementById(textfield1).value;
    textbox2= document.getElementById(textfield2).value;

    var isEmpty=new String();

    rs.Open("SELECT count(*) as pers FROM clie HAVING N_CLIENT =" + textbox1+ " AND C_POST_CLIE = '" + textbox2+ "'",connection);

    alert(rs.recordcount);
    //alert(rs.fields(1));
    //isEmpty = rs.Open("pers");
    alert("Empty"+isEmpty);
    if(pers=0)
        alert("Record does not exist! pers="+pers);
    else if(pers=1)
        alert("Record exists! pers="+pers);
    else
        alert("not working");
    rs.close;
    connection.close;
    }
}
4

2 回答 2

2

尝试这个:

rs.Open("SELECT count(1) as pers FROM clie Where N_CLIENT =" + textbox1+ " AND C_POST_CLIENT = '" + textbox2+ "'",connection)

您可以通过以下方式检索 pers 字段:

perCounts = rs.('pers')

或者

perCounts = rs.("pers")

然后如果 perCounts = 0 则用户不存在....如果 1 则用户存在于您的数据库中。

_ _ ____编辑_ __ _ __ _ __ _ __ _ ___

function RecordExists(textfield1, textfield2)
{
var connection = new ActiveXObject("ADODB.Connection") ;
var connectionstring = "UID=admin;PWD=password";
connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");
var textbox1= new String();
var textbox2=new String();
textbox1= document.getElementById(textfield1).value;
textbox2= document.getElementById(textfield2).value;

var isEmpty=new String();

rs.Open("SELECT count(*) as pers FROM clie HAVING N_CLIENT =" + textbox1+ " AND C_POST_CLIE = '" + textbox2+ "'",connection);

alert(rs.recordcount);

rs.MoveFirst();

perCounts = rs.Fields(0).Value;


if(perCounts=0)
    alert("Record does not exist! pers="+pers);
else if(perCounts=1)
    alert("Record exists! pers="+pers);
else
    alert("not working");
rs.close;
connection.close;
}
}

萨卢多斯。

于 2013-02-27T14:52:23.190 回答
0

您应该改用 count 方法

rs.Open("SELECT count(*) FROM clie Where N_CLIENT =" + textbox1+ " AND C_POST_CLIENT = '" + textbox2+ "'",connection)

这将返回结果的数量

0 = 0 客户 1 = 1 客户 2 = 2 客户。. .

于 2013-02-27T15:04:04.097 回答