你不用: if (ClientDataSet1.ChangeCount>0) or (ClientDataSet1.State in [dsinsert,dsedit]) then
begin //要更新数据了
if ClientDataSet1.Applyupdate(0)>0 then showmessage('更新成功了');
end;
pfInWhere, pfInKey 例子
a, b, c 都设为 pfInWhere
cds 中改动了 a, b, c 中任一个数值时, ApplyUpdates(-1)
MIDAS 自动生成的更新语句是
update table set a = new_value_a, (可能 b = new_value_b, c = new_value_c 看你是否改动了)
where a = old_value_a, b = old_value_b, c = old_value_c
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
只设 a 为 pfInWhere 时, 上面的 where 语句将是这样
where a = old_value_a
^^^^^^^^^^^
pfInUpdate 例子
上面的例子中如果设 b 没有 pfInUpdate 则不管在 ClientDataSet 中是否改动了 b 的值,都不会有 b = new_value_b 的语句出现,不幸的是 ClientDataSet 不能得知 b 的值没有被更新,我没有什么好的解决方法,刷新 ClientDataSet 或在服务端中 b 的 field editor 中设 readonly = true