In this example, we use a function to load a table of our database to DropDownListBox Power Builder.
For our example we will use the NorthWind database
Before starting with our example, we spend a few concepts:
SetRedraw:
Controls automatic redrawing of an object or control after each change in its properties.
Return Value: Integer. Returns 1 if successful and -1 if an error occurs. Boolean If NULL, returns null SetRedraw.
Syntax:
objectname.SetRedraw (boolean)
Reset:
Removes all elements from a list. Can be used with the ListBox, DropDownListBox, PictureListBox, and DropDownPictureListBox.
Return Value: Integer. Returns 1 if successful and -1 if an error occurs. If control is null, the Reset returns null. The return value is not used.
Syntax:
objectname.Reset ()
Let us design our form:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1dKQWmqwv48DnKUclUVJhd3fds2AulusnPhp45cMpyT8M2EChyqeyFitc8v8F_Tl1WJTKcCNGHiHzhXESvMGc0x5zfT047VGafO50kfA_swpnLPCV_vqgLId7TgkEMoqPNY3QJ5vaQ04/s400/2009-09-30_233329.jpg)
We declare our variables intance Variable type: string
ls_select_string, ls_add_string
Now let's create our function with the name of f_llenar_ddlb :
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcRnyiM_1qQB2JxUBeCrXhRRUQgZ63oVofBW-tLBAWFRgnmxE0eK1EZxFhIjGNnSiZ82ymN4ZjVDdpZNWC3b5osTcV3_7QxwzmF1H5zZHkNAFBWmGEUZU5pGIOf5zqM6JXWIupjbIcUIc/s400/ddlb.jpg)
Then script for the function:
ls_select_string = "SELECT DISTINCT "+ columna_param +" FROM "+ tabla_param +" "+ where_param
sqlsa PREPARE FROM: ls_select_string;
dyn_cursor DYNAMIC DECLARE CURSOR FOR sqlsa;
OPEN DYNAMIC
dyn_cursor;
SQLCA.SQLCODE
< 0 then
if MessageBox (" Error Base data! "sqlca.sqlerrtext)
SQLCA.SQLCODE
return end if
ddlb_param.SetRedraw (false)
ddlb_param.Reset () Do While
SQLCA.SQLCODE = 0
Fetch dyn_cursor into: ls_add_string;
if sqlca . sqlcode = 0 then
ddlb_param.AddItem (ls_add_string) elseif
SQLCA.SQLCODE < 0 then
MessageBox ("Database Error", sqlca.sqlerrtext) Else return SQLCA.SQLCODE
exit end if Loop
ddlb_param.SetRedraw (true)
Close dyn_cursor;
return 0
now to view our data in the table, we call our function that we created, and we must write our script in the event the windows open:
f_llenar_ddlb ('categories', 'categoryName' ddlb_categoria,'')
compiled and run the windows:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGEGctNk5n3zYlFAN8GfBXMuXNbILknYELTB4fKcqVPyG9ceeCTb0f5dm-f0CFs5jbj5KZoUUW05P_fEviNxgOHC4wfjE0uTp7y94nu5wGGKGQAmzT3Abt3sC71IZJVjaph-UsNnE5uPQ/s400/2009-09-30_233512.jpg)