tags:

views:

404

answers:

2

I programming with adodb/dbgo and try to use this code:

procedure TfrMain.dbeNoMejaKeyPress(Sender: TObject; var Key: Char);
begin
  dmWarbam.TblTrans_temp.Filtered := False;
  dmWarbam.TblTrans_temp.Filter := 'ID_ITEM = ' + QuotedStr(dbeNoMeja.Text);
  dmWarbam.TblTrans_temp.Filtered := True;
end;

and

procedure TfrMain.dbeNoMejaChange(Sender: TObject);
begin
  dmWarbam.TblTrans_temp.Filtered := False;
  dmWarbam.TblTrans_temp.Filter := 'ID_ITEM = ' + QuotedStr(dbeNoMeja.Text);
  dmWarbam.TblTrans_temp.Filtered := True;
end;

But none of above can work, when i press key on dbeNoMeja it didn't filter but instead the dataset inserting broken/incomplete data to database.

Can someone give me some example that working (full code)

A: 

Code example adapted from Delphi-Neftalí. Nice and simple!

procedure TForm1.Edit1Change(Sender: TObject);
begin

  // incremental search
  ClientDataSet1.Locate('FirstName', Edit1.Text, [loCaseInsensitive, loPartialKey]);
  Exit;

  // actual data filtering
  if (Edit1.Text = '') then begin
    ClientDataSet1.Filtered := False;
    ClientDataSet1.Filter := '';
  end
  else begin
    ClientDataSet1.Filter := 'FirstName >= ' + QuotedStr(Edit1.Text);
    ClientDataSet1.Filtered := True;
  end;

end;


Setting ClientDataSet's provider to ADO DB (in your case):

  Path := ExtractFilePath(Application.ExeName) + 'Data.MDB';
  // Exist the MDB?
  if FileExists(path) then begin
    ClientDataSet1.ProviderName := 'DSProvider';
    ADOQ.Open;
    ClientDataSet1.Active := True;
    ADOQ.Close;
    ClientDataSet1.ProviderName := '';
    lbldata.Caption := ExtractFileName(path);
    Exit;
  end;
Olaf
i never though that we will use clientdataset in ado programming, any other solution that don't require use of clientdataset?
Dels
+2  A: 

If the dbedit is connected to the same table as the one you want to filter you have a problem, because the table goes into the dsEdit state once you start entering text.

Use a normal TEdit, and append a wildcard (*) to the string in the filter

dmWarbam.TblTrans_temp.Filter := 'ID_ITEM = ' + QuotedStr(edtNoMeja.Text+'*');
Jan Oosting
wow thanks for pointing me, so i must use TEdit instead TDBEdit, i guess that could solve that problem
Dels