小
小乙
Unregistered / Unconfirmed
GUEST, unregistred user!
前提是这样:
生成了五个数据库,每个数据库装有各年的每个月的气象信息共12个月表,年是1998--2002年,
我要设计一个数据浏览窗口,按下确定按钮自动显示所选时间对应的信息,我采用的是ADO数据集
连接ACCESS数据库,需要提示的是每个表(*.db)的文件名前分别是如199801.db...前面是年后面
代表月份所建立的名。我采用的是这样的设计:在窗体上放置两个RadioGroupBox,第一个放5个“年”;
第二个放12个月,建立5个表(1998k.db...),每个表装每年的12个月的数据表名,然后根据第一个
RadioGroupbox的焦点打开对应的数据库表,根据第二个RadioGroupBox的焦点移动数据库表的记录指针,
从而找到打开对应的表,代码清单如下:
unit ShowData;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, DBCtrls, Db, DBTables, ADODB;
type
TShowDataForm1 = class(TForm)
Label1: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
RadioGroup1: TRadioGroup;
RadioGroup2: TRadioGroup;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
ADOTable2: TADOTable;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
ShowDataForm1: TShowDataForm1;
implementation
{$R *.DFM}
procedure TShowDataForm1.BitBtn1Click(Sender: TObject);
begin
case RadioGroup1.ItemIndex of
0: ADOTable1.TableName:='1998k';
1:ADOTable1.TableName:='1999k';
2:ADOTable1.TableName:='2000k';
3:ADOTable1.TableName:='2001k';
4:ADOTable1.TableName:='2002k';
end;
With RadioGroup2 do
begin
ADOTable1.Open;
ADOTable1.RecNo:=RadioGroup2.ItemIndex+1;//根据表1内记录指针对应表2
ADOTable2.TableName:=ADOTable1.FieldS[1].AsString;
ADOTable2.Open;
ShowForm.Show;
end;
end;
procedure TShowDataForm1.BitBtn2Click(Sender: TObject);//关闭
begin
AdoTable1.Close;
ADOTable2.Close;
Application.Terminate;
end;
end.
生成了五个数据库,每个数据库装有各年的每个月的气象信息共12个月表,年是1998--2002年,
我要设计一个数据浏览窗口,按下确定按钮自动显示所选时间对应的信息,我采用的是ADO数据集
连接ACCESS数据库,需要提示的是每个表(*.db)的文件名前分别是如199801.db...前面是年后面
代表月份所建立的名。我采用的是这样的设计:在窗体上放置两个RadioGroupBox,第一个放5个“年”;
第二个放12个月,建立5个表(1998k.db...),每个表装每年的12个月的数据表名,然后根据第一个
RadioGroupbox的焦点打开对应的数据库表,根据第二个RadioGroupBox的焦点移动数据库表的记录指针,
从而找到打开对应的表,代码清单如下:
unit ShowData;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, DBCtrls, Db, DBTables, ADODB;
type
TShowDataForm1 = class(TForm)
Label1: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
RadioGroup1: TRadioGroup;
RadioGroup2: TRadioGroup;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
ADOTable2: TADOTable;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
ShowDataForm1: TShowDataForm1;
implementation
{$R *.DFM}
procedure TShowDataForm1.BitBtn1Click(Sender: TObject);
begin
case RadioGroup1.ItemIndex of
0: ADOTable1.TableName:='1998k';
1:ADOTable1.TableName:='1999k';
2:ADOTable1.TableName:='2000k';
3:ADOTable1.TableName:='2001k';
4:ADOTable1.TableName:='2002k';
end;
With RadioGroup2 do
begin
ADOTable1.Open;
ADOTable1.RecNo:=RadioGroup2.ItemIndex+1;//根据表1内记录指针对应表2
ADOTable2.TableName:=ADOTable1.FieldS[1].AsString;
ADOTable2.Open;
ShowForm.Show;
end;
end;
procedure TShowDataForm1.BitBtn2Click(Sender: TObject);//关闭
begin
AdoTable1.Close;
ADOTable2.Close;
Application.Terminate;
end;
end.