📄 unit9.pas
字号:
unit Unit9;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, ADODB, StdCtrls,Unit2,Unit8, ExtCtrls,
Buttons;
type
TForm9 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
ADOQuery1: TADOQuery;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Label1: TLabel;
Edit1: TEdit;
BitBtn1: TBitBtn;
GroupBox3: TGroupBox;
DataSource2: TDataSource;
DBGrid2: TDBGrid;
ADOQuery2: TADOQuery;
Label2: TLabel;
GroupBox4: TGroupBox;
Label3: TLabel;
Label4: TLabel;
procedure FormActivate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure DBGrid1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form9: TForm9;
implementation
{$R *.dfm}
procedure TForm9.FormActivate(Sender: TObject);
begin
ADOQuery1.Connection :=DataModule2.ADOConnection1 ;
ADOQuery2.Connection :=DataModule2.ADOConnection1 ;
ADOQuery1.SQL.Clear ;
ADOQuery1.SQL.Add('select * from 寝室表'); //获得寝室表信息
ADOQuery1.Open;
end;
procedure TForm9.BitBtn1Click(Sender: TObject);
begin
ADOQuery1.Close ; //查询该寝室的所有信息
ADOQuery1.SQL.Clear ;
ADOQuery1.SQL.Add('select * from 寝室表 where 寝室号='''+Edit1.Text +'''');
ADOQuery1.Open;
if not ADOQuery1.IsEmpty then
begin
ADOQuery2.Close; //获得相应寝室的学生信息
ADOQuery2.SQL.Clear ;
ADOQuery2.SQL.Add('select 学生信息表.姓名,学生信息表.班级,学生信息表.系别 from 学生信息表,学生寝室表 where 学生寝室表.寝室号='''+Edit1.Text+''' and 学生寝室表.学号=学生信息表.学号');
ADOQuery2.open;
end;
end;
procedure TForm9.DBGrid1DblClick(Sender: TObject);
begin
ADOQuery2.Close; // 双击寝室信息表(DBGrid1)中的纪录,得到相应寝室所住的同学信息
ADOQuery2.SQL.Clear ;
ADOQuery2.SQL.text :='select 学生信息表.姓名,学生信息表.班级,学生信息表.系别 from 学生信息表,学生寝室表 where 学生寝室表.寝室号=:A and 学生寝室表.学号=学生信息表.学号';
ADOQuery2.Parameters.ParamByName('A').Value :=ADOQuery1.fieldByName('寝室号').AsString;
ADOQuery2.Prepared ;
ADOQuery2.open;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -