if you dont want to use datamodule or the component
try something like that;
why use datamodules while you can directly call them
just like in vb6
sdb := TSQLQuery.Create(nil);
cndb := TODBCConnection.Create(nil);
stran := TSQLTransaction.Create(nil);
stran.DataBase := cndb;
stran.Action := caCommit;
stran.Active := True;
cndb.Transaction := stran;
cndb.Open;
rsdb.DataBase := cndb;
rsdb.SQL.Text := 'SELECT * FROM Table1';
rsdb.Open;
my another sample
TDBClass = class
private
// a data set to mantain all templates of database
dsQuery: TSQLQuery;
// the connection object
mycon: TMYSQL40Connection;
// SQL Transaction
SQLTransact: TSQLTransaction;
public
function openDB(): boolean;
procedure closeDB();
procedure clearDB();
end;
implementation
...
...
...
// TdbClass Usage
// Open connection
function TDBClass.openDB(): boolean;
begin
try
dsQuery := TSQLQuery.Create(nil);
mycon := TMySQL40Connection.Create(nil);
SQLTransact := TSQLTransaction.Create(nil);
mycon.UserName := 'root';
mycon.HostName := 'localhost';
mycon.port := 3306;
mycon.DatabaseName := 'XXX';
SQLTransact.DataBase := mycon;
SQLTransact.Action := caCommit;
SQLTransact.Active := True;
dsQuery.DataBase := mycon;
mycon.Transaction := SQLTransact;
mycon.Open;
openDB := true;
except
openDB := false;
end;
end;
