Advanced PowerBuilder

HomePrevious Lesson: SELECT INTO
Next Lesson: The INSERT Statement

The UPDATE Statement

You can explicitly execute an UPDATE statement through Embedded SQL. For example, in the w_transactions window in our application, you have to update the product_balance in product_master table for each transaction, i.e., receipt, return or receipt. Calling the Update() function for the DataWindow would update the transaction table trans but not product_master unless you have defined triggers on the trans table in the database. The alternate solution from the client application is update 'product_master' table using Embedded SQL as shown in the following example:
UPDATE "product_master" 
SET "product_balance" = product_balance + :lQuantity
WHERE product_no = :li_ProductNo;
If SQLCA.SQLNRows <> 1 Then
   RollBack Using SQLCA;
   SQLCA.uf_display_error()
   Return 0
End If

To find the number of rows affected by the UPDATE statement, we can check SQLCA.SqlNRows after the UPDATE command is successfully executed.
HomePrevious Lesson: SELECT INTO
Next Lesson: The INSERT Statement