首頁  >  文章  >  專題  >  access刪除空白欄位記錄

access刪除空白欄位記錄

王林
王林轉載
2020-12-01 15:46:573303瀏覽

access刪除空白欄位記錄

首先我們需要知道在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中文網其他相關文章!

陳述:
本文轉載於:csdn.net。如有侵權,請聯絡admin@php.cn刪除