## DBFields

DBFields, or database fields, are fields directly from databases, user data sources, hierarchical data sources, or XML data sources.

### Inserting a DBField in a report

DBFields can be inserted in the report areas listed in Component placement.

To insert a DBField into a report, you can use either of the following two ways:

- Using dialog
  1. Position the mouse pointer at the destination where you want to insert the DBField and do one of the following:
     - Click Insert > DBField on the menu bar.
     - Click the Insert DBField button on the Insert toolbar.

     The Insert Fields dialog appears. See the dialog.

  2. Select a dataset from the dataset drop-down list, and all resources in the selected dataset will then be listed in the DBField List box.
  3. Select the required DBField and specify its layout in the Insert Layout box as required.
  4. Click the Insert button to insert the DBField into the destination.
- By dragging and dropping

  Select the required DBField from the Resource View panel, then drag it to the destination.

When a DBField has been inserted into a report, you can customize its appearance and behavior by setting properties in the Report Inspector, which can be saved as a CSS style for future use (for details, see Creating a CSS style).

Notes:

- To insert more than one DBField with the Insert Field dialog, you can select them one by one with the Ctrl key, or you can make a continuous selection with the Shift key.
- You cannot use the Insert Fields dialog to insert a DBField into a crosstab.
- If you insert a DBField into the detail panel of a banded object or table, the name of the DBField will automatically be inserted as a label into the corresponding header panel. Otherwise the field and its name label will be placed in the same panel. If you do not want to insert the field name automatically, you can go to the Options dialog, select Component in the Category box and then uncheck the Insert field name label with field option.

### Adding a summary for a DBField

To add a summary for a DBField:

1. Right-click the DBField and select Summary Function from the shortcut menu.
2. In the Insert Summary dialog, specify the summary settings according to your requirements.
3. When done, click Insert.

For more information, see Inserting a summary in a report.

### Changing the display type of a DBField

The display type of a DBField can be changed according to your requirements, that is to say, you can map the DBField to another value or image to be displayed instead.

To change the display type a DBField:

1. Right-click the DBField and select Display Type from the shortcut menu.
2. In the Display Type dialog, specify the required display type in the Type box, and set the options for the selected type in the Option panel.
3. Upon finishing, click the OK button to close the dialog.

For details about display types, see Changing the display type of a label.

### Binding a link to a DBField

You can make a DBField linked with another report, a URL or an e-mail. To do this:

1. Right-click the DBField and select Detail Report on the shortcut menu to display the Master/Detail Report dialog.
2. From the Link to drop-down list, specify the target to which the DBField will be linked.
3. Set the options for the target according to your requirements.
4. When done, click OK.

For details about different link targets, see Binding a link to a label.

### Adding conditional formats to a DBField

You can add some conditional formats to a DBField, then when the specified condition is fulfilled, the defined format will be applied to the field values for distinguishing.

To add conditional formats to a DBField:

1. Select the DBField and then do one of the following:
   - Click Format > Conditional Formatting on the menu bar.
   - Click the Conditional Formatting button on the Format toolbar.
   - Right-click the DBField and select Conditional Formatting from the shortcut menu.

   The Conditional Formatting dialog appears. See the dialog.

2. Click the button , then in the Edit Conditions dialog, define the condition as required. See the dialog.

   1. Click the Add Condition button to add a condition line.
   2. From the field drop-down list, select the field on which the condition will be based.
   3. Choose the operator with which to compose the condition expression from the operator drop-down list.
   4. From the value drop-down list, specify the value of how to build the condition. You can also type in the value manually.
   5. Click Add Condition to add another condition line and define the relationship between the two condition lines if required.
   6. When done, click OK to save the condition.

   The newly added condition will then be displayed in the Condition box in the Conditional Formatting dialog.

3. In the Format box, set the format which will be applied to values of the DBField when the specified condition is fulfilled, for example, the font face, font size, font color, etc.
4. Repeat the above steps to add more conditions and define the format for each condition as required.
5. When done, click OK to save the settings.

See also Conditional Formatting dialog and Edit Conditions dialog for details about options in the dialogs.

See an example: The SampleComponents catalog, included with JReport Designer, contains reports that have examples of how each component type could be used in a report. For the DBField component example, open `<install_root>\Demo\Reports\SampleComponents\ForDBField.cls`.