0

你好,我是 delphi 7 的新手,我已经编写了一个管理我的 mdb 数据库的应用程序。我只想放置一个搜索框,如果我输入一个关键字,它将在数据库的特定行上返回带有关键字的结果。

示例:在名为 first name 的行上,我想使用 john 关键字搜索数据库,然后当我按 Enter 或搜索按钮时,应用程序将返回结果,其中包含名字中包含 john 的所有数据

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;

编辑:

我已经这样做了:

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.

到目前为止,我可以提取所有表格数据。我想要我的程序做的是显示我在 tedit 上输入的数据

顺便说一句,我的第一篇文章很抱歉,我仍然不熟悉论坛的快捷方式和发帖规则。:D

4

2 回答 2

1

TDataSet.FilterTDataSet.OnFilterRecord 或直接使用 SQL。

于 2013-03-16T11:00:01.887 回答
0

得到它只是一些小问题,但也许我能弄清楚

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 := '';
于 2013-03-18T11:22:29.610 回答