| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 870 人关注过本帖
标题:我这简单的三层哪里错了?
只看楼主 加入收藏
Button
Rank: 1
等 级:新手上路
帖 子:17
专家分:7
注 册:2009-9-14
结帖率:50%
收藏
 问题点数:0 回复次数:0 
我这简单的三层哪里错了?
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.
搜索更多相关主题的帖子: class procedure Windows private 
2010-03-26 08:12
快速回复:我这简单的三层哪里错了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015239 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved