我当然试过了的
你试试这个:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB;
type
TForm1 = class(TForm)
Button1: TButton;
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
DBGrid1: TDBGrid;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function test(Q:TADOQuery):boolean;
begin
Q.Close;
Q.SQL.Text:='Select * from employees';
Q.Open;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
test(ADOQuery1);
end;
end.
=========
object Form1: TForm1
Left = 192
Top = 103
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 176
Top = 344
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object DBGrid1: TDBGrid
Left = 104
Top = 112
Width = 465
Height = 225
DataSource = DataSource1
TabOrder = 1
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object DataSource1: TDataSource
DataSet = ADOQuery1
Left = 272
Top = 128
end
object ADOQuery1: TADOQuery
ConnectionString =
'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security In' +
'fo=False;Initial Catalog=Northwind'
Parameters = <>
Left = 208
Top = 120
end
end