| Home | Previous Lesson: Database Independence Next Lesson: Retrieving Data from the Database |
It allows you to connect to multiple databases within an application, at the same time. You can create multiple transaction objects and connect to various databases for each DataWindow.
We do this in the Open script for the window, by using the SetTransObject() function. So add the following lines to the Open event script for the w_product_master window:
// Event: Open
// Object: w_product_master
dw_product.SetTransObject( SQLCA)
dw_query.SetTransObject( SQLCA)
Note that there is another function which allows you to set the transaction object - SetTrans(). If you use this function, you don't have to call Connect statement, but, you loose control over transaction management and the application automatically connects and disconnects to the database whenever the Retrieve() or Update() functions are called. When you use SetTransObject(), it gives you more control over the transactions. That means, you need to take care of connecting to the database; as we did in the cb_ok CommandButton script in the w_login window. Please note that, in both the cases, you need to populate SQLCA object. You will be learning more about transaction management in later sessions.
The major problem in using SetTrans() is that, continually connecting and disconnecting to a database takes both time and processor power, and resources on both the client machine as well as on the database server machine.
Recall painting the w_product_master window in the window painter exercises? As explained in the window painter, a DataWindow control is a container for a DataWindow object. If there is no DataWindow object sitting in the DataWindow control, then the DataWindow control is of no use to us. The reason we didn't assign DataWindow objects is that, the DataWindow objects weren't ready by DataWindow painter session. No problem, let's do it now.
Go to the properties of dw_product and type d_products_maint for DataWindow Object Name prompt and click OK CommandButton. Similarly assign d_product_custom_query for dw_query DataWindow control.
| Home | Previous Lesson: Database Independence Next Lesson: Retrieving Data from the Database |