DataSnap使用UniDac处理自增长字段

原来使用ado来访问数据库,用在DataSnap中也很方便。后来便一直使用UniDac,可发现UniDac如果用在DataSnap中要比ado麻烦很多,尤其对自增长字段、缺省值的处理上,感觉对DataSnap支持不好(普通C/S应用还是非常好的)。

在Unidac官网上看到一个关于处理DataSnap中的AutoInc字段问题,记录在下面,我没有验证。

I use DataSnap delphi 2010.

UniQuery Component DMLRefresh Can fetch autoinc value,

but I cannot use it with datasnap.

I use Follow Code.

procedure TForm.dspDataAfterUpdateRecord(Sender: TObject; SourceDS: TDataSet; DeltaDS: TCustomClientDataSet; UpdateKind: TUpdateKind); begin if UpdateKind = ukInsert then quData.Fields[0].NewValue := GetLastID; end;

GetLastID function is fetch autoinc value.

the code works grate with DBExpress. But not UniDac.

 

Answer:

 

To solve this problem, it's needed to set the following options:
Code: Select all
TDataSetProvider.ResolveToDataSet := True;
TUniQuery.RequiredFields := False;
TUniQuery.SetFieldsReadOnly := False;In this case UniDAC will generate the SQL code, and the identity field value will be set automatically to the TUniQuery component. To update the identity field value in the TClientDataSet, component it's needed to use the following code:
Code: Select all
procedure TForm1.DataSetProvider1AfterUpdateRecord(Sender: TObject; SourceDS: TDataSet; DeltaDS: TCustomClientDataSet; UpdateKind: TUpdateKind);
begin
  if UpdateKind = ukInsert then
    DeltaDS.Fields[0].NewValue := UniQuery1.Fields[0].AsInteger;
end;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值