Create a second DataWindow object

Where you are

   Create and preview a new DataWindow object

   Save the DataWindow object

   Make cosmetic changes to the first DataWindow object

>   Create a second DataWindow object

   Make cosmetic changes to the second DataWindow object

When you built the first DataWindow object, you used Quick Select to specify the table and columns. This let you retrieve all the customers without having to use the Select painter.

To build the second DataWindow object, you use the Select painter. You need to define a retrieval argument and WHERE criteria so you can pass an argument to the DataWindow object during execution. In this case, you will pass the customer ID.

In this section, you:

Select the data source and style

Now you select a data source and define how the data is to be presented.

  1. Click the New button () in the PowerBar.

    The New dialog box appears.

  2. Click the DataWindow tab if it is not already selected.

    Select Freeform from the list of presentation styles and click OK.

  3. Select SQL Select as the data source and select the Retrieve On Preview check box if it is not already selected.

    Since the data source is SQL Select, you go to the Select painter and the Select Tables dialog box displays.

    Selecting the Retrieve On Preview check box allows you to view the data returned by a query in the development environment, but you need to provide initial values for any retrieval arguments that you specify.

  4. Click Next.

Select the table and columns

Now you select the table and the columns to use in the DataWindow object.

  1. Select customer in the list of tables and click Open.

    The Select painter displays the customer table and its columns.

    Alternative method

    If you double-click the customer table instead of selecting it and clicking Open, the Select Tables dialog box remains open. In this case, you must click Cancel to continue.

  2. Right-click the header area in the Table Layout view.

    Choose Select All from the pop-up menu.

    The column names appear in the Selection List area above the table. 

    The columns appear in the order in which you selected them. Because you selected all the columns at once, the original order of the columns in the database is used. You change the column presentation order later.

You can also see the selection order in the Syntax view: click the Syntax tab at the bottom of the stack of tabbed panes to display the generated Select statement.

Define a retrieval argument

Now you define a retrieval argument.

  1. Select Design>Retrieval Arguments from the menu bar.

    The Specify Retrieval Arguments dialog box displays. 

  2. Type cust_id in the Name box.

    The default data type is Number, which is what you want.

    About retrieval argument names

    You can choose any name you want for the retrieval argument; it is just a placeholder for the value you pass during execution. Nonetheless, it is a good idea to make the name meaningful.

  3. Click OK.

    The retrieval argument is defined.

Specify a WHERE clause

Now you specify a WHERE clause using the retrieval argument to retrieve a specific customer.

  1. Click the Where tab in the stack.

    The Where view displays.

  2. Click in the box below Column in the Where view.

    A down arrow displays, and the box becomes a drop-down list box.

  3. Select "customer"."id".

    Your selection displays immediately below the Column heading. An equal sign (=) appears in the Operator box. This is correct, so do not change it.

  4. Right-click in the box below the Value column header in the Where view.

    Select Arguments from the pop-up menu, select :cust_id, and click Paste.

  5. Click the Syntax tab in the stack.

    The Syntax view displays the modified SELECT statement.

  6. Scroll down until you see the generated WHERE clause.

    You have now created a complete SQL SELECT statement that retrieves data from several columns in the customer table where the id column is equal to an argument that will be supplied during execution.

View the DataWindow in the DataWindow painter

Now you view the DataWindow in the DataWindow painter using the Design and Preview views.

  1. Click the Return button in the PainterBar


    Select File>Return To DataWindow Painter from the menu bar.

    The DataWindow wizard asks you to select the borders and colors for the new DataWindow object.

  2. Select Raised from the Border drop-down list box for columns.

    Click Next.

    You have added raised borders to the DataWindow columns, but not to the labels. The DataWindow wizard summarizes your selections.

  3. Click Finish.

    Because you selected the Retrieve On Preview check box and because the Preview view is part of the default layout scheme for the DataWindow painter, the Specify Retrieval Arguments dialog box appears.

    This dialog box prompts you for an argument value. When you put this DataWindow object into the tutorial application, you write a script that passes the required argument to the DataWindow object automatically.

  4. Type a customer ID (such as 101, 102, or 103) in the Value field.

    Click OK.

    The DataWindow painter opens. The Design view displays the new DataWindow object.

Changing font sizes

If you cannot see all letters in a label, press Ctrl+A to select all the items in the DataWindow, then select a smaller font size in the StyleBar.

The DataWindow Preview view retrieves the requested customer data.

Retrieving other records

If you want to preview the record for another customer, you can right-click inside the DataWindow Preview view, select Retrieve from the pop-up menu, then specify a different customer ID in the Specify Retrieval Arguments dialog box.

Save the DataWindow object

Now you name the DataWindow object and save it. You could wait to save it until you leave the painter, but it is good practice to save your work frequently.

  1. Select File>Save from the menu bar.

    The Save DataWindow dialog box displays.

  2. Make sure pbtutor.pbl is selected in the Application Libraries box.

    Type d_customer in the DataWindows box.

    Earlier you saved a DataWindow object as d_custlist.

  3. (Optional) Type the following comments in the Comments box.

    This DataWindow retrieves all columns for the Customer table. It is useful as a detail DataWindow.
  4. Click OK.

    You return to the DataWindow painter.