我这简单的三层哪里错了?
unit Unit1;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, Grids, DBGrids;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
const sql = 'select * from 参数表';
var data : Variant;
err: string;
begin
if Dm.QuerySQL(sql, data, err) then
ClientDataSet1.Data := data
else
MessageBox(Self.Handle,PChar('查询数据出错:'+err),'错误',MB_OK+MB_ICONERROR);
end;
end.
unit Unit2;
interface
uses
SysUtils, Classes, Provider, DB, ADODB;
type
TDm = class(TDataModule)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSetProvider1: TDataSetProvider;
private
{ Private declarations }
public
function ApplyUpdates(const UpateTable:string;Detla:Variant;out err:string):Boolean;
function QuerySQL(const sqlstr:string; out data:Variant; err:string):Boolean;
end;
var
Dm: TDm;
implementation
{$R *.dfm}
function TDm.ApplyUpdates(const UpateTable:string;Detla:Variant;out err:string):Boolean;
const sql = 'select * from %s where 1 <> 1';
var
sqlstr : string;
Errcount : Integer;
begin
Result := False;
sqlstr := Format(sql, [UpateTable]);
try
ADOConnection1.BeginTrans;
ADOQuery1.Close;
ADOQuery1.SQL.Text := 'sqlstr';
ADOQuery1.Open;
DataSetProvider1.ApplyUpdates(Detla, -1, Errcount);
Result := Errcount = 0;
if Result then
else ADOConnection1.RollbackTrans;
except
on E: Exception do
begin
ADOConnection1.RollbackTrans;
err := E.Message;
end;
end;
end;
function TDm.QuerySQL(const sqlstr:string; out data:Variant; err:string):Boolean;
begin
Result := False;
try
ADOQuery1.close;
ADOQuery1.sql.text := sqlstr;
ADOQuery1.Open;
Data := DataSetProvider1.data;
Result := True;
except
on E: Exception do
err := E.Message;
end;
end;
end.