delphi三层结构常出现的问题和解决方案

以下问题出现原因有可能多个,暂时将我遇见的记录下来,以后有新的在陆续更新上去,有网友愿意的话也可以共同测试一下。

一,无法更新定位行。一些值可能已在最后一次读取已更改。

错误出现前提

1, 录数据时,没有输或忘记输一些列就保存,之后重新修改记录,输入这些值后保存出现错误。

2, 多个人同时修改记录,后保存的几个人会出现。

分析原因:

1, 这种错误通常在数据库表中某一个或几个字段存在默认值,而在录的过程跳过了默认值列的输入,导致保存后记录显示和数据库不一致,保存会出现。

2, 第二种情况不用解释了,因为错误提示得很清楚。

解决方法:

1, 取消数据库表原先存在默认值的列的默认值。真的需要默认值的话,就在after
insertbefore post事件里将默认值的列赋值。或者保存后刷新记录;

2,关于多人修改的问题,没办法解决;

二,unable to find recordNo Key specified

错误出现前提:

1,修改状态下,删除或者修改自己数据,保存发现。

分析原因:

1ProviderupdateModel设置为upwhereAll,数据中存在日期字段,而且该字段还是用数据库的getdate()去获取的,delphi的日期是不包含毫秒,而数据库却包含了,这样就造成前后数据不一致的原因;

2ProviderupdateModel设置为upWhereKeyOnly,没有设置子集的主键,导致更新或删除找不到主键;

解决方法:

1,设置子集的主键,假设为id

在子集的before
post事件里写入以下语句:

PS:ADODet是子集,CDSDet是中间层,即TClientDataSet

if CDSDet.State in [dsinsert] then
begin
with ADODet.FieldByName('id') do
    ProviderFlags := ProviderFlags - [ pfInKey ];
end
else if CDSDet.State in [dsedit] then
begin
with ADODet.FieldByName('id') do
  ProviderFlags := ProviderFlags + [ pfInKey ];
end;

在子集的before
delete事件里写

with ADODet.FieldByName('id') do
    ProviderFlags := ProviderFlags + [ pfInKey ];

三,Key Violation

错误出现前提:

1,修改子集保存过一次的状态下,重新修改子集,新增记录,超过一条的(第二条保存时)出现;

分析原因:

1,数据库表存在自增列,假设为id,在新增记录时,子集无法及时获取新的id,照成保存时出现主键重复的问题;

解决方法:

1,定义全局变量FID:integer=-1,在子集的before
post或者On new Record事件中写:

if CDSDet.State in [dsinsert]
then
begin
CDSDet.Fields.Fields[i].ReadOnly:=False;
CDSDet.Fields.Fields[i].AsInteger:=FID;
Dec(FID);
end;


转载于:https://www.cnblogs.com/fyen/archive/2011/03/13/1982879.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Delphi 7.1 Update Release Notes=======================================================This file contains important supplemental and late-breakinginformation that may not appear in the main productdocumentation, and supersedes information contained in otherdocuments, including previously installed release notes.Borland recommends that you read this file in its entirety.NOTE: If you are updating a localized version of Delphi 7, visit the Borland Registered User web site to obtain a localized readme file that may contain important late- breaking information not included in this readme file.IMPORTANT: Delphi must be closed before installing this update. =====================================================CONTENTS * INSTALLING THIS UPDATE * UPDATING LOCALIZED VERSIONS OF DELPHI 7 * KNOWN ISSUES * ISSUES ADDRESSED BY THIS UPDATE - IDE - CORE DATABASE - DATASNAP - DBGO (ADO COMPONENTS) - dbExpress - dbExpress COMPONENTS AND DB VCL - dbExpress CORE DRIVER AND METADATA - dbExpress VENDOR ISSUES - dbExpress CERTIFICATION - WEB SNAP - ACTIVEX - COMPILER - RTL - VCL - THIRD PARTY - BOLD FOR DELPHI * VERIFYING THAT THE UPDATE WAS SUCCESSFUL * FILES INSTALLED BY THIS UPDATE =======================================================INSTALLING THIS UPDATE* This update can not be applied to Delphi 7 Architect Trial version. * This update can not be removed after it is installed.* You will need the original Delphi 7 installation CD available to install this update.* To install this update from the CD, insert the CD, and launch the d7_ent_upd1.exe file appropriate for your locale.* To install this update from the Web, double-click the self-executing installation file and follow the prompts. * The Delphi 7 documentation PDF files are available on the update CD.========================================================UPDATING LOCALIZED VERSIONS OF DELPHI 7* This update can be applied only to the English version of Delphi 7. There are separate updates for the German, French and Japanese ver

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值