To :qinmingzsj
SQL Server数据库中 主表与从表设置了主从级联
服务器端没有什么函数、过程,只是一个远程模块,添加了主从关系的数据集,数据源。
unit rdm;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
DBClient, Project1_TLB, StdVcl, DB, ADODB, MConnect, SConnect, Provider;
type
TDM = class(TRemoteDataModule, IDM)
MyDB: TADOConnection;
QyMaster: TADOQuery;
QyDetail: TADODataSet;
dsMaster: TDataSource;
DpMD: TDataSetProvider;
QyTemp: TADOQuery;
DpTemp: TDataSetProvider;
QyMasterID: TIntegerField;
private
{ Private declarations }
protected
class procedure UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
override;
public
{ Public declarations }
end;
implementation
{$R *.DFM}
class procedure TDM.UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
begin
if Register then
begin
inherited UpdateRegistry(Register, ClassID, ProgID);
EnableSocketTransport(ClassID);
EnableWebTransport(ClassID);
end else
begin
DisableSocketTransport(ClassID);
DisableWebTransport(ClassID);
inherited UpdateRegistry(Register, ClassID, ProgID);
end;
end;
initialization
TComponentFactory.Create(ComServer, TDM,
Class_DM, ciMultiInstance, tmApartment);
end.
客户端:
unit client;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, SConnect, StdCtrls, Grids, DBGrids;
type
TForm1 = class(TForm)
sc: TSocketConnection;
cdsMaster: TClientDataSet;
DsMaster: TDataSource;
dsDetail: TDataSource;
cdsDetail: TClientDataSet;
dgmaster: TDBGrid;
dgdetail: TDBGrid;
btnAdd: TButton;
Button1: TButton;
cdsTemp: TClientDataSet;
cdsMasterID: TIntegerField;
cdsMasterQyDetail: TDataSetField;
procedure btnAddClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnAddClick(Sender: TObject);
var ID :integer;
begin
With cdsTempdo
begin
close;
FileName := '';
CommandText := 'Select Max(ID) from Master';
Open;
if Not cdstemp.Fields[0].isNull then
id:= cdstemp.Fields[0].AsInteger+1
else
ID := 1;
end;
With cdsMasterdo
begin
Append;
FindField('ID').AsInteger:= ID ;
Post;
end;
With cdsDetail do
begin
Append;
FindField('ID').AsInteger:= ID ;
FindField('Qty').AsInteger :=10;
Post;
end;
if cdsMaster.ApplyUpdates(0)>0 then
begin
showmessage('保存出错 !');
abort;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
try
sc.Open;
except
showmessage('连接失败!');
abort;
end;
with cdsMasterdo
begin
Close;
FileName :='';
CommandText := 'Select * from SalH Where 1<>1';
ProviderName := 'DpMd';
Open;
//SaveToFile(Application.ExeName+'a4.cds');
end;
end;
end.
初做三层,不知主从关系要如何做?