Introduction to PowerBuilder

HomePrevious Lesson: Exporting Data to Another Format
Next Lesson: Sharing Data between DataWindows

Querying the Database Dynamically

When the user clicks on the Query button, we would like to give him/her a chance to input the query criteria and retrieve the data based on the given input.

// Object: cb_query for w_product_master
// Event: clicked
dw_query.BringToTop = TRUE
dw_query.modify('datawindow.querymode = yes')

We need to put dw_product in the query mode. The DataWindows dealt till now were in regular mode. Changing the DataWindow to query mode inserts about ten blank rows and allows the user to provide a query criteria. Once the user types in the query criteria, (s)he is going to retrieve the data by clicking on the Retrieve CommandButton. Change the Clicked event code for the cb_retrieve CommandButton as follows:
// Object: cb_retrieve in w_product_master window
// Event: Clicked
dw_product.BringToTop = TRUE
dw_query.AcceptText()
dw_query.Modify("DataWindow.QueryMode=no")
dw_query.Retrieve()

The above code brings dw_product DataWindow control to the front and puts dw_query into regular mode and retrieves data from the database. You might have observed a new function, AcceptText(). By default, PowerBuilder doesn't take the changed value of the field in which the cursor is present, unless the user press tab key or clicks on some other field. Since we are not going to ask the user to press tab after entering data in each field, call AcceptText() to take the changed value, even the current field also.

Here's something to speculate. Did you find anything wrong in the above code? No! Don't worry, the code's fine, otherwise you couldn't have compiled it anyway. The problem is that we are retrieving data in dw_query, but it is hiding behind dw_product. Then how is the user going to see the data? Let's solve this problem in the next section.

Please note that QueryMode doesn't work on DataWindows with presentation styles Composite, External, Crosstab and Graph. It will also generate runtime error when QueryMode is turned on secondary DataWindows while sharing the data.
HomePrevious Lesson: Exporting Data to Another Format
Next Lesson: Sharing Data between DataWindows