locate这个函数发现用起来很麻烦啊。想用locate函数来判断数据库中
是否存在某一条记录时是一个很好的方法,其他的如根据返回记录数
recordcount也可以。当我数据库连的是access的时候,可以有返回值;当
改为sql server时,出了问题,查看返回值时,提示是:EVariantError
at $797F981。因此,locate下面的语句就没有被执行到了。不知道哪位老大能提供点意见。
程序如下:
{从数据库中找出用户名字为userslist.items[usersptr]}
sqlstr:='select users_id from users where users_name='+''''+userslist.Items[userptr]+'''';
with customerdata.Query1 do begin
close;
sql.Clear;
unprepare;
sql.Add(sqlstr);
try
open;
except
end;
if active=true then begin
{如果存在users这条记录}
if locate('users_id',userslist.Items[userptr],[])=false then
result:=false;
end;
是不是 KeyValues 参数不对?
這是取回第一個子項的Caption.試試,不要說Locate 不好用啦。它沒什麼錯誤的。
這個就返回當前的子項的Caption;
你试试用具体的值看看
locate('UserId','具体值',[])
result:=false
else
if customerdata.Query1.locate('users_id',userslist.Items[userptr],[])=false then
result:=false;
end;
end;