updateSql 控件的使用

updateSql 这个控件在我刚学 delphi 时就知道了,但不直不会用,上网也没有找到过例子,今天正好需要用到这

个控件,一用,还真好用,呵呵,说一下它的使用方法吧

updateSql 这个控件原本是用来更新不同的表的,当用 query 打开了多个表,但这时就不能直接用 query 来更新

表的操作了,因为里面是多个表,这里就用 updateSql 这个控件了,把 query 的 updatObject 指向一个

updateSql,同时这个 query 的 cacheUpdates 为 true,我试着用 false 试了试,在 dbgrid 里不能输入数据。

我这里query 只打开了一张表,开始试着把 RequestLive 设为 true ,但 open 时,提示 can not find object

上网搜搜是什么意思,但没有找到答案,国外的站点提到这个问题,是说 sql 数据库中用了 Nchar,或 nvarchar

数据类型,但我没有用呀,不知为什么,于是就想到了 updateSql ,还没用过呢,先试试吧,设好属性后, open

,没有提示了,好,改变数据 再 applyUpdates  ,出错了,因为没有 modifySql ,但这个 modifySql 该怎么写

呢?查了查 联机帮助


Specifies the SQL UPDATE statement to use when applying an update to a record and cached updates is

enabled.

property ModifySQL: TStrings;

Description

Set ModifySQL to the SQL UPDATE statement to use when applying an updated record to a dataset.

Statements can be parameterized queries. To create a UPDATE statement at design time, use the

UpdateSQL editor to create statements, such as:

UPDATE "Country.db"

SET Name = :Name, Capital = :Capital, Continent = :Continent

WHERE Name = :OLD_Name

At run time, an application can write a statement directly to this property to set or change the

UPDATE statement.

Note: As the example illustrates, ModifySQL supports an extension to normal parameter binding. To

retrieve the value of a field as it exists prior to application of cached updates, the field name

with “OLD_? ”This is especially useful when doing field comparisons in the WHERE clause of the

statement.


看得虽不太明白,但也明白点了,就是更新表时,用     字段 =:字段  但条件呢 也就是 where 该怎么写呢

它在下面说了 用 OLD_字段名,按它说的做做 , applyUpdates ,没有错,再打开数据库看看,哎,数据更新了

 

到这里,我知道该怎么用 updateSql 了

 

注意一下的是

写 sql 语句时 如 set name =: name , sex =: sex  这样就不可以,必须去掉空格,要不会出现 Field '' is of

an unknown  type 的提示,不知为什么它不会自已去掉这些空格

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值