Hyderabad Jobs Book Website FREE PowerBuilder Training I Love Hyderabad Hyderabad Colleges
Home Business Emails Hyderabad Classifieds Contact Us
7 Wonders of Hyderabad Web Hosting Yellow Pages Our Network

 
Webpowerbuilder.hyderabad-colleges.com

Advanced PowerBuilder

HomePrevious Lesson: DropDown/Child DataWindows
Next Lesson: Dynamic DataWindows

Modifying DDDW Dynamically

All attributes you set in the DropDownDataWindow Edit Style dialog box can be modified using the Modify() function. The important attributes that can be modified using this method include:

  • name
  • data column
  • display column

For example, to make "unit" column as the display column for the above DropDown DataWindow, you would write the following code:
datawindowchild dwc1
dwc1.Modify( "product_measuring_unit.dddw.displaycolumn=~"unit~"")
dwc1.Settransobject( sqlca )
dwc1.retrieve( /* Arguments */ )

In the above Modify() function, product_measuring_unit is the column name, and "dddw.displaycolumn" is the property of the column to change. In the exercise we just did, d_products_maint is called as 'Parent DataWindow', and d_units_dropdown is called as 'Child DataWindow'. When you issue Retrieve()on the parent DataWindow, PowerBuilder automatically retrieves data for the child DataWindow, using the same transaction object you set either in the SetTrans() or in the SetTransObject().

Irrespective of the number of rows in the DataWindow, PowerBuilder retrieves data from the child DataWindow only once.

The important point to remember about Child DataWindow is that, PowerBuilder doesn't retrieve data from the child DataWindow, if the child DataWindow contains at least one row; the row can even be an empty one.

Sometimes, you may want to bring data into the child DataWindow using a different transaction object. For example, say product_master table is in Sybase and units table is in Informix. Assume that we are using SQLCA to connect to Sybase and created a new transaction object for Informix (we will explain about creating a new transaction in a moment).

When you issue Retrieve(), as we said, PowerBuilder automatically tries to retrieve data using the transaction object of the parent. Here, our units table is in Informix, and is not existing in the connected Sybase database. Hence, it will fail. How do we solve this problem?

Here's a tip for you. Recall "Storing data in the DataWindow" topic. Put what we said above and this together, and you should have no problem solving it. If you are not able to, then read the following, you can do it otherwise also.

What we said early was that, if a child DataWindow already has some data in it, PowerBuilder doesn't retrieve from the child DataWindow. Now the problem is, how to store data in the child DataWindow, without retrieving from the database. The solution is, open child DataWindow in the DataWindow painter, select "Rows/Data" from the menu and insert a blank row and save it. Now that a blank row is part of it, PowerBuilder doesn't retrieve from the child DataWindow. Then, how to retrieve data using transaction object created for "Informix".
DataWindowChild l_UnitChildDw
integer l_ReturnCode
l_ReturnCode = dw_product.GetChild( &
              'product_measuring_unit', l_UnitChildDw )
IF l_ReturnCode = -1 THEN Return 0
// Establish the connection if not already connected
// We assume that this transaction object was already populated.
CONNECT USING G_TranForInformix;
// Set the transaction object for the child
l_UnitChildDw.SetTransObject( G_TranForInformix )
// Populate the child DataWindow
l_UnitChildDw.Retrieve()
CONNECT USING SQLCA;
dw_product.SetTransObject(SQLCA)
dw_product.Retrieve()

In the above code, we declared a variable of type DataWindowChild. Then we are calling GetChild() function to get a reference to the child DataWindow associated with the product_measuring_unit column. Then, we connected to the Informix database, using the transaction object created for it and retrieved the data. As you can see from the code, we are using SQLCA for the parent DataWindow.

We know that you still have a question for us, "How to create our own Transaction Object"? The answer is simple, use the CREATE statement.
Transaction G_TranForInformix
G_TranForInformix = CREATE Transaction
// Assign variables with values, for ex:
// G_TranForInformix.DBMS = "Informix"
HomePrevious Lesson: DropDown/Child DataWindows
Next Lesson: Dynamic DataWindows

Copyright © 1996 - 2006 HamaraShehar.com Pvt. Ltd. All Rights Reserved.
Domain Registration, Website Design, Website Hosting by HamaraShehar.com