0% found this document useful (0 votes)
8 views2 pages

Connection Code

Uploaded by

osanabakaing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Connection Code

Uploaded by

osanabakaing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

unit dmHouses_u;

interface

uses
System.SysUtils, System.Classes,ADODB,DB;

type
TdmHouses = class(TDataModule)
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
connDB: TAdoConnection;

tblProperties: TADOTable;
dsrProperties: TDataSource;

tblClients: TADOTable;
dsrClients: TDataSource;

tblAgents: TADOTable;
dsrAgents: TDataSource;

qryHouse: TADOQuery;
dsrQryHouse: TDataSource;
end;

var
dmHouses: TdmHouses;

implementation

{%CLASSGROUP 'Vcl.Controls.TControl'}

{$R *.dfm}

procedure TdmHouses.DataModuleCreate(Sender: TObject);


begin
//Instantiate or create the componenets on the datamodule
connDB:= TAdoConnection.Create(dmHouses);

tblProperties:= TADOTable.Create(dmHouses);
dsrProperties:= TDataSource.Create(dmHouses);

tblClients:= TADOTable.Create(dmHouses);
dsrClients:= TDataSource.Create(dmHouses);

tblAgents:= TADOTable.Create(dmHouses);
dsrAgents:= TDataSource.Create(dmHouses);

qryHouse:= TADOQuery.Create(dmHouses);
dsrQryHouse:= TDataSource.Create(dmHouses);

//Connection code to Database


connDB.ConnectionString :=
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' +
ExtractFilePath(ParamStr(0)) + 'PAT2024.mdb' +
'; Persist Security Info=False';
connDB.LoginPrompt := False;
connDB.Open;

//Linking database tables


tblProperties.Connection := connDB;
tblProperties.TableName := 'tblProperties';
tblClients.Connection := connDB;
tblClients.TableName := 'tblClients';
tblAgents.Connection := connDB;
tblAgents.TableName := 'tblAgents';

//linking the datasource


dsrProperties.DataSet := tblProperties;
dsrClients.DataSet := tblClients;
dsrAgents.DataSet := tblAgents;

//linking SQL with Database


//NOTE- you only need ONE query object to use with all the sqls
qryHouse.Connection := connDB;
dsrQryHouse.DataSet := qryHouse;

//Opening tables
tblProperties.Open;
tblClients.Open;
tblAgents.Open;
end;

end.

You might also like