
首先我们需要知道在Access中null和空字符串是不同的,因此如果处理不好该问题就会带来不少麻烦,特别是在混合查询中。
(推荐教程:access数据库学习)
解决方法如下:
var
SQLStr:string;
begin
//
SQLStr := 'select * from ordertb where 1>0';
if Trim(Edit1.Text)<>'' then
SQLStr := SQLStr +' and serialid like :a';
if Trim(Edit2.Text)<>'' then
SQLStr := SQLStr +' and pname like :b';
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add(SQLStr);
if Trim(Edit1.Text)<>'' then
Parameters.ParamByName('a').Value := '%'+Trim(Edit1.Text)+'%';
if Trim(Edit2.Text)<>''then
Parameters.ParamByName('b').Value := '%'+Trim(Edit2.Text)+'%';
Open;
end;
end;或者:
begin
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from ordertb where 1>0');
if Trim(Edit1.Text)<>'' then
SQL.Add(' and serialid like ''%'+Trim(Edit1.Text)+'%''');
if Trim(Edit2.Text)<>''then
SQL.Add(' and pname like ''%'+Trim(Edit2.Text)+'%''');
Open;
end;
end;总结:
将条件为空的字段从查询语句中过滤掉。
以上就是access删除空字段记录的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号