updateSql 控制項的使用

來源:互聯網
上載者:User

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 的提示,不知為什麼它不會自已去掉這些空格

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.