关于delphi中用adoquery进行模糊查询

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:47   2445   0

我们知道在delphi中进行查询时,因为查询条件有时候复杂我们会选择这样的方式:

 
ADOQuery1.Close;
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add('select * from customerInfo where customerId like :id');
    ADOQuery1.Parameters.ParamByName('id').Value :=  eCustomerId.text;
    ADOQuery1.Open;



但是当面临需要写多重模糊查询时比如说like '%a%'这样的形式的时候,就发现不好写了,是这样的吗?

ADOQuery1.Close;
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add('select * from customerInfo where customerId like% :id%');
    ADOQuery1.Parameters.ParamByName('id').Value :=  eCustomerId.text;
    ADOQuery1.Open;
执行的时候会发现不能识别参数id了。
比较讨巧的方式是这样的:
ADOQuery1.Close;
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add('select * from customerInfo where customerId like :id');
    ADOQuery1.Parameters.ParamByName('id').Value :=  ‘%’+eCustomerId.text+‘%’;
    ADOQuery1.Open;




分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP