PowerBuilder's Data Window object is its unique intelligent object, its encapsulation is good, the function is formidable, the manifestation form is rich and diverse, for this reason, many MIS developers regard PowerBuilder as the preferred development tool.
Under normal circumstances, a data window can only update a database table, but in the MIS development process, we often encounter this situation: a data window by two or more database tables as a data source, and need to input or modify it, How to give the general solution of multiple table update becomes an unavoidable problem for MIS development personnel. In the process of developing a management information system, the author tries several kinds of dual-table updating methods to choose a better scheme and readers.
First, the concrete steps
1. When the data window is established, choose SQL Select, which can be either tabular, grid, or freeform. Select two tables that need to be entered or modified, where the primary key and Non-empty columns of the two tables must be selected, determine the selection criteria, and establish a connection relationship.
2. Select all the data items in the first table in the menu "Rows/update" as updatable items.
3. Change the tab order value of the two tables to a non-0 value to make it modifiable in the data window.
In order to make the scheme universal, set up the global function f-update-2table, there are five parameters: Dw-obj, table1, table2, Key1, Key2, respectively, representing the data window to be updated, two table table names and two table primary key column names, where dw- obj is of type DataWindow and the remaining four parameters are of type string. The return value of the function is Boolean, and True indicates success, and returning false indicates failure.
Second, the function of thinking
1. Call Update function update for first database table first. Note the use of parameters: the first parameter action is to control the data window before the mandatory call Accepttext (), in the data window before updating through validation; The second parameter is the reset of the control update flag, and the update flag is reset when True, and the update flag is not bit when false.
2. Change the Updatetable property of the data window so that it points to the second table, and change the key property of the data item Update property and primary key column of the first table to No, and then change the key property of each data item update property and primary key column of the second table to Yes.
3. Call the update function to update the second table.
4. After the two tables have been successfully updated, the column properties of the two tables and the primary key properties are changed back to the original state to prepare for the next two-table update call.