unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, DBCtrls, Grids, DBGrids, DB, ADODB;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBEdit1: TDBEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
DBGrid1: TDBGrid;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
newstring:string;
begin
inputQuery('输入查询条件','姓名为',newstring);
self.ADOTable1.Locate('Sname',newstring,[loCaseInsensitive]) //精确查询
end;
procedure TForm1.Button2Click(Sender: TObject);
var
newstring:string;
begin
inputQuery('输入查询条件','姓名为',newstring);
self.ADOTable1.Locate('Sname',newstring,[loPartialKey]) //模糊查询
end;
procedure TForm1.Button3Click(Sender: TObject);
var
newstring:string;
begin
inputQuery('输入查询条件','姓名为',newstring);
self.ADOTable1.Filter:='Sname='+''''+newstring+'''';
self.ADOTable1.Filtered:=true;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
newstring:string;
begin
inputQuery('输入查询条件','姓名为',newstring);
self.ADOTable1.Filter:='Sname like ' + ''''+'%'+newstring+'%'+'''';
self.ADOTable1.Filtered:=true;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
self.ADOTable1.DisableControls;
if
messageDlg('确实要删除这条记录吗?',mtinformation,[mbok,mbcancel],0)=mrOk
then
self.ADOTable1.Delete;
self.ADOTable1.EnableControls;
end;
end.