unit dASP;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ComObj, StdCtrls, ExtCtrls, Grids, DBGrids, DB,ADODB;type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
DBGrid1: TDBGrid;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
AConnection,ARecordSet:variant;
longintTemp : integer;
strTemp,strSQL: string;
intIndex : integer;
begin
//strSQL:='StuInfo';
strSQL:='SELECT 学号,姓名,性别 FROM StuInfo';
AConnection:=CreateOleObject('Adodb.connection');
//AConnection.Open('Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\Sample\20040710\Student');
AConnection.Open('DSN=qlTEST');
ARecordSet:=CreateOleObject('Adodb.recordset');
ARecordSet.open(strSQL,AConnection);
//Self.DBGrid1.DataSource:=ARecordSet;(为什么这句话不可以?)
ARecordSet.close;
AConnection.close;
end;end.
我想通过程序用ADODB动态连接Access数据库,生成的纪录集送给DBGrid.DataSource,为什么不可以?应该怎么写,注意我的控件是DBGrid,不是StringGrid,不要告诉我借用AdoConnection控件和AdoDataSet控件,我的目的是想通过程序将查询出来的纪录集送到DBGrid中,我个人不习惯在设计阶段去设置那些控件的属性,我感觉很不爽?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ComObj, StdCtrls, ExtCtrls, Grids, DBGrids, DB,ADODB;type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
DBGrid1: TDBGrid;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
AConnection,ARecordSet:variant;
longintTemp : integer;
strTemp,strSQL: string;
intIndex : integer;
begin
//strSQL:='StuInfo';
strSQL:='SELECT 学号,姓名,性别 FROM StuInfo';
AConnection:=CreateOleObject('Adodb.connection');
//AConnection.Open('Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\Sample\20040710\Student');
AConnection.Open('DSN=qlTEST');
ARecordSet:=CreateOleObject('Adodb.recordset');
ARecordSet.open(strSQL,AConnection);
//Self.DBGrid1.DataSource:=ARecordSet;(为什么这句话不可以?)
ARecordSet.close;
AConnection.close;
end;end.
我想通过程序用ADODB动态连接Access数据库,生成的纪录集送给DBGrid.DataSource,为什么不可以?应该怎么写,注意我的控件是DBGrid,不是StringGrid,不要告诉我借用AdoConnection控件和AdoDataSet控件,我的目的是想通过程序将查询出来的纪录集送到DBGrid中,我个人不习惯在设计阶段去设置那些控件的属性,我感觉很不爽?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货