unit uDBGrid;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, DBGrids, StdCtrls,
DBCtrls, odbcconn,odbcsqldyn, SQLDB, DB,ComCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
ODBCConnection1:TODBCConnection;
SQLTransaction1:TSQLTransaction;
SQLQuery1:TSQLQuery;
DataSource1:TDataSource;
ComboBox1: TComboBox;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
Function ShowMSG(const M:String;But:TMsgDlgButtons=[mbOK]):Boolean;
private
public
end;
var
Form1: TForm1;
implementation
uses utoolkit;
{$R *.lfm}
{ TForm1 }
Function TForm1.ShowMSG(const M:String;But:TMsgDlgButtons=[mbOK]):Boolean;
begin
Result:=False;
if MessageDlg(M, mtInformation , But,1) in [mrYes,mrOK] then
Result:=True;
end;
procedure TForm1.FormActivate(Sender: TObject);
var
r,p:Integer;
e,f,ps:String;
begin
ODBCConnection1:=TODBCConnection.Create(ODBCConnection1);
ODBCConnection1.DatabaseName:='Access64';
f:=ExtractShortPathName('G:\t\Dad\Program Files\Lazarus\projectsessions\test\MainHelp.mdb');
ODBCConnection1.Connected:=false;
ODBCConnection1.KeepConnection:=false;
e:=ExtractFileExt(F);
ODBCConnection1.DatabaseName:='Access64';//ODBC Manager
if ODBCConnection1.Params.Count>0 then
for r:=0 to ODBCConnection1.Params.Count-1 do
begin
P:=pos('DBQ=', ODBCConnection1.Params[r]);
if p>0 then
ODBCConnection1.Params[r]:='DBQ='+F
end
else
ODBCConnection1.Params.Add('DBQ='+F);
Try
ODBCConnection1.Connected:=TRUE;
ODBCConnection1.KeepConnection:=TRUE;
except
on E: Exception do
ShowMSG('An exception was raised: ' + E.Message);
end;
ODBCConnection1.LogEvents:=[];
SQLTransaction1:=TSQLTransaction.Create(SQLTransaction1);
SQLTransaction1.DataBase:=ODBCConnection1;
SQLTransaction1.Action:=caCommit;
ODBCConnection1.Transaction:=SQLTransaction1;
SQLQuery1:=TSQLQuery.Create(SQLQuery1);
SQLQuery1.DataBase:=ODBCConnection1;
SQLQuery1.Transaction:=SQLTransaction1;
SQLQuery1.AutoCalcFields:=TRUE;
SQLQuery1.Options:=[sqoAutoApplyUpdates,sqoAutoCommit,sqoKeepOpenOnCommit];
SQLQuery1.Upda]"]>Blockedde:=upWhereAll;
SQLQuery1.UsePrimaryKeyAsKey:=false;
SQLQuery1.DataBase:=ODBCConnection1;
SQLQuery1.Transaction:=ODBCConnection1.Transaction;
DataSource1:=TDataSource.Create(DataSource1);
DataSource1.Dataset:= SQLQuery1;
DBGrid1.DataSource:=DataSource1;
DBNavigator1.DataSource:=DataSource1;
PS:= 'SELECT * FROM HLPMain';
try
SQLQuery1.Close;
SQLQuery1.SQL.Text:=ps;
SQLQuery1.Open;
except
on E: Exception do ShowMSG(ps);
end;
end;
procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
DataSource1.Free;
SQLQuery1.Free;
SQLTransaction1.Free;
ODBCConnection1.Free;
end;
end.