powerbuilder datawindow / sql query...

Posted on 2004-11-08
Last Modified: 2013-12-26
how can i use one datawindow in order sql query to be displayed in it?

I have two buttons on a form. According to the button you press different output will show up in the same datawindow. The same table from an oracle database will be used. Only one field is going to be changed.

query1: select that from there where field=10
query2: select that from there where field=20


is this somehow possible?

The datawindow will be the same.
Question by:stefanosn
    LVL 33

    Expert Comment

    A simple option would be to select field1,field2 from there where field =:as_argument.

    Then based on the argument( if it is always 10 or 20 ) or based on the clicked button ( you could pass some distinct value) based on which you could then make visible/invisible the field and the header text.


    Both text2 and output2 will be overlapping text1 and output1 respectively.
    Just set the visible propert to 1 or 0 based on that condition of whichevr button is selectd

    Author Comment


    these two lines i use to call the datawindow from the first button
    the query created with teh wizard...

    how can i define on the second button what query i want to run?
    i have to do it from the wizard again and somehow call it?

    LVL 5

    Expert Comment

    Are you asking about retrieval arguments?  All columns in the result set and where clause are the same and you just want the criteria to have a different value?

    In the datawindow painter when defining or editing the SQL, on the menu go to Design->Retrieval Arguments.  You can define as many as you want.  Then, when defining the WHERE clause, you can put :argumentName in place of the value.

    Author Comment

    under the second button what should i write? to call the second argument

    Author Comment

    i have a query

    select username from users where a=1
    select username from users where a=2

    these two queries

    i want the first query to run if i press the first button
    i want the second query to run if i press the second button


    the output will show on the same datawindow...according to the button i press

    is this possible?
    LVL 33

    Accepted Solution

    your retrieval will be with some arguments. So define a retreival argument in the sql.
    Your sql query would look like
    select field1,field2 from there where field =:as_argument.

    In the first button retrieve as
    dw_1.retrieve(as_argument.) and similarly in the second button you will be having
    So basically retrieve passing an argument.
    LVL 1

    Assisted Solution

    Of course!
    In the datawindow you need to define a retrieval argument: click on the SQL button and then in the menu Design->Retrieval Arguments and create an argument called as you want for example "my_value" and select the type of data then, if you are in the graphic view select the menu View->Where and in column select the field of your table wich will be the condition for the retrieve (a in your case), in operator '=' and in value write :my_value
    Your query must be:
    select username from users where a=:my_value in the syntaxis view of the datawindow

    Then in the button 1 write this code:
    and in the button 2 write:
    LVL 4

    Assisted Solution


    Do the following:

    1. Open your window where you have datawindow and two buttons.
    2. Now place your mouse on the datawindow and click the right mouse button.
    3. Now select the modify datawindow from popup menu
    4. Now select the sql button from the toolbar
    5. Now select 'retrieval arguments' from menu 'Design'.
    6. give the retrieval argument say ret_value as number or as you need
    7. Now from the same menu 'Design' select convert to syntax
    8. Here you will find the syntax and you will see the argument WHERE this = that (If not then write)
    where column_name = :ret_value (You can do it also in Graphic mode. You can see in lower area some tabs as Sort Where Group Having etc. here you can select where and select the column and then in the value with the right mouse button select the argument and give ret_value with double click when you will see the given value in the retrieval arguments.
    9. (if you are in syntax mode then only)Now menu 'design' and select convert to graphic
    10. in the constructor event of you datawindow write:
    11. In your button one clicked event write:

    Long  ll_retvalue

    ll_retvalue = 1 //or which value you want
    dw_1.Retrieve(ll_retvalue) //which value you have for button 1

    //do for the button 2 also the same
    Long  ll_retvalue

    ll_retvalue = 2

    dw_2.Retrieve(ll_retvalue) //which value you have for button 2

    If you any question please let me know.


    Best regards


    Assisted Solution

    It maight be better to use a filter approach.  You can retrieve the data only once, apply the filter, then display the results.  Could be quicker and definitely cheaper with respect to database connections/overhead.

    Create a function that has string argument and returns an integer

    Parent.f_dwfilter ( "value" )  // pass either the 1 or 2

    Function f_dwfilter
    string ls_avalue //this could be integer, long, etc, depending on the value being passed - make sure that
                           //that you change the argument type
    integer li_returncode

    ls_avalue = as_avalue

    dw_1.SetRedraw ( False )
    string ls_dwFilter

    ls_dwFilter = "a= '" + ls_avalue + "' "

    li_returncode = dw_1.Filter( )

    dw_1.SetReDraw ( True )

    Return li_returncode

    This is off the top of my head, but it should work.  Please let me know if you have any more questions.  the only caveat to this, is that if data changes after the data window has been retrieved, you will not see that data.  But as it seems that this is a display window only, then this should work faster.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
    How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from ( Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
    The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now