[
]V3.22版本在完善ORM的同时,也完善了Delta提交方式的远程数据库交互功能,使习惯于DBGrid形式编程的应用程序员也能方便地进行远程数据库访问。下面是示例代码://// 读远程数据...procedure TForm1.Button2Click(Sender: TObject);
begin
syncburro1.TargetDatabase:='smartsales';
if qbclientdataset1.ReadFromRemote(qbconnection1.NodeId,'select * from material order by materialid') then
// if qbclientdataset1.ReadFromRemote(qbconnection1.NodeId,'select MaterialId,MaterialName,Model,MUnit,PUnit,PScale,BuyPrice,SalePrice,MemberPrice,CostPrice,Number from material order by materialid') then
begin
qbclientdataset1.Last;
materialid:=trim(qbclientdataset1.fieldbyname('MaterialId').asstring);
memo1.lines.Add('从远程读数据列表成功!');
end else
memo1.lines.Add('从远程读数据列表失败啦!');
end;
//// 新增一个记录...procedure TForm1.Button7Click(Sender: TObject);
begin
//// 得到一个新的ID... materialid:=inttostr(strtoint(materialid)+1);
while length(materialid)<8do
materialid:='0'+materialid;//// 写入一个记录... qbclientdataset1.Append;
qbclientdataset1.FieldValues['MaterialId']:=materialid;
qbclientdataset1.FieldValues['MaterialName']:='飞快牌柴刀'+materialid+'号';
qbclientdataset1.FieldValues['Model']:='木柄地';
qbclientdataset1.FieldValues['MUnit']:='把';
qbclientdataset1.FieldValues['PUnit']:='捆';
qbclientdataset1.FieldValues['PScale']:=10;
qbclientdataset1.FieldValues['BuyPrice']:=20;
qbclientdataset1.FieldValues['SalePrice']:=28;
qbclientdataset1.FieldValues['MemberPrice']:=26;
qbclientdataset1.FieldValues['CostPrice']:=25;
qbclientdataset1.FieldValues['Number']:=10;
qbclientdataset1.post;
end;
//// 修改当前记录...procedure TForm1.Button3Click(Sender: TObject);
begin
//// 修改一个记录... qbclientdataset1.edit;
qbclientdataset1.FieldValues['MaterialName']:='飞快牌菜刀';
qbclientdataset1.FieldValues['Model']:='木柄';
qbclientdataset1.FieldValues['MUnit']:='柄';
qbclientdataset1.FieldValues['PUnit']:='捆';
qbclientdataset1.FieldValues['PScale']:=100;
qbclientdataset1.FieldValues['BuyPrice']:=200;
qbclientdataset1.FieldValues['SalePrice']:=280;
qbclientdataset1.FieldValues['MemberPrice']:=260;
qbclientdataset1.FieldValues['CostPrice']:=250;
qbclientdataset1.FieldValues['Number']:=100;
qbclientdataset1.post;
end;
//// 删除当前选中记录...procedure TForm1.Button6Click(Sender: TObject);
begin
qbclientdataset1.Delete;
end;
//// 提交测试...procedure TForm1.Button4Click(Sender: TObject);var code,err: string;
begin
memo1.Lines.Add('QBClientDataset的数据有'+inttostr(qbclientdataset1.ChangeCount)+'处变化!');
DeltaCds.Data:=qbclientdataset1.Delta;
deltacds.SaveToFile('c:/delta.xml',dfxml);
memo1.Lines.Add('Delta数据已经保存到c:/delta.xml,请检查!');// if qbclientdataset1.CommitToRemote(qbconnection1.NodeId,'Material','MaterialId') then
memo1.lines.Add('数据已经提交到远程数据库!') else
begin
memo1.lines.Add('数据提交失败喽!');
syncburro1.GetLastError(code,err);
memo1.Lines.Add('Code='+code+' Error='+err);
end;
end;