Chunk Chunk
Chunk Chunk

Reputation: 143

database search box

hello i am just new to delphi 7 and i have written a app which manages my mdb database. i just want to put a search box wherein if i put in a keyword it will return results with the keyword on a specific row of the database.

example: on the row named first name i want to search the database with the john keyword then when i hit enter or search button the app will return results with all the data containing john on its first name

type
    Tcollector = class(TForm)
    Image1: TImage;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    procedure DataSource1DataChange(Sender: TObject; Field: TField);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  collector: Tcollector;

implementation

{$R *.dfm}

procedure Tcollector.DataSource1DataChange(Sender: TObject; Field: TField);
begin

end;

EDIT:

i have done this:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls;

type
    TForm1 = class(TForm)
    ComboBox1: TComboBox;
    ADOConnection1: TADOConnection;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Button1: TButton;
    Button2: TButton;
    ADOQuery2: TADOQuery;
    ADOQuery3: TADOQuery;
    ADOQuery4: TADOQuery;
    ADOQuery5: TADOQuery;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
ADOConnection1.GetTableNames(ComboBox1.Items);
end;

procedure TForm1.Button1Click(Sender: TObject);
var  tblname : string;
begin

if ComboBox1.ItemIndex < 0 then Exit;
tblname := ComboBox1.Items[ComboBox1.ItemIndex];

with ADOQuery1 do begin
Close;
  SQL.Text := 'SELECT * FROM ' + tblname;
  Open;
end;

with ADOQuery2 do begin
  Close;
  SQL.Text := 'SELECT * FROM ' + tblname;
  Open;
end;

with ADOQuery3 do begin
  Close;
  SQL.Text := 'SELECT * FROM ' + tblname;
  Open;
end;

with ADOQuery4 do begin
  Close;
  SQL.Text := 'SELECT * FROM ' + tblname;
  Open;
end;

with ADOQuery5 do begin
  Close;
  SQL.Text := 'SELECT * FROM ' + tblname;
  Open;
end;

    end;
procedure TForm1.Button2Click(Sender: TObject);
begin
form2.show;
end;

end.

so far i can pull all the table data. what i want my program to do is to display data which i have typed on a tedit

btw sorry for my first post im still not familiar with the forum shortcuts and rules on posting. :D

Upvotes: 0

Views: 2846

Answers (2)

Chunk Chunk
Chunk Chunk

Reputation: 143

got it just some minor problems but maybe i can figure it out

begin
ADOTable1.First;
if ADOTable1.Locate('Last',edit1.Text ,[]) then begin
Label1.Caption := ADOTable1.FieldByName('Last').AsString;
Label2.Caption := ADOTable1.FieldByName('First').AsString;
Label3.Caption := ADOTable1.FieldByName('address').AsString;
Next;
end else begin
Label1.Caption := '';
Label2.Caption := '';
Label3.Caption := '';

Upvotes: 0

Abelisto
Abelisto

Reputation: 15624

TDataSet.Filter or TDataSet.OnFilterRecord or use SQL directly.

Upvotes: 1

Related Questions