Export (0) Print
Expand All

Setting the Data Environment

Visual Studio .NET 2003

Each form or set of forms includes a data environment. The data environment is an object that includes the tables or views the form interacts with and the relationships between tables that the form expects. You can visually design the data environment in the Data Environment Designer and save it with the form.

The data environment can automate opening and closing tables and views when the form is run. In addition, the data environment helps you set the ControlSource property for controls by populating the ControlSource property-setting box in the Properties window with all the fields in your data environment.

To open the Data Environment Designer

  1. From the View menu, choose Data Environment.
  2. From the Shortcut menu, choose Add.
  3. In the Open dialog box, choose a table or view to add to the data environment.

Common Data Environment Properties

The following data environment properties are commonly set in the Properties window:

Property Description Default Setting
AutoCloseTables Controls whether tables and views are closed when the form is released. True (.T.)
AutoOpenTables Controls whether tables and views in the data environment are opened when the form is run. True (.T.)
InitialSelectedAlias Specifies the table or view that is selected when the form is run. "" at design time. If not specified, at run time the first cursor added to the DataEnvironment is initially selected.

Adding a Table or View to the Data Environment Designer

When you add tables or views to the Data Environment Designer, you can see the fields and indexes that belong to the table or view.

To add a table or view to the Data Environment Designer

  1. From the View menu, choose Data Environment.
  2. From the Data Environment menu, choose Add.
  3. In the Add Table or View dialog box, select a database in the Database box.
  4. In the Select area, choose Tables or Views.

    Your selection determines which fields list appears in the Tables in database box.

  5. In the Tables in Database box, select a table or view.
  6. Choose OK.

    -or-

    If no database or project is open, choose Other to select a table.

You can also drag a table or view from an open project or the Database Designer into the Data Environment Designer.

Setting an Index for the Data Environment Designer

You can set the order your records appear in your report by setting an index for the data environment.

To set an index for the Data Environment Designer

  1. From the View menu, choose Data Environment.
  2. From the shortcut menu, choose Properties.
  3. In the Properties Window, choose Cursor1 in the Object box.
  4. Choose the Data tab and select the Order property.
  5. Enter an index name.

    -or-

    Select an index from the list of available indexes.

When the Data Environment Designer is active, the Properties window displays objects and properties associated with the data environment. Each table or view in the data environment, each relationship between tables, and the data environment itself is a separate object in the Object box of the Properties window.

Removing a Table from the Data Environment Designer

When you remove a table from the data environment, any relationships that the table is involved in are also removed.

To remove a table or view from the Data Environment Designer

  1. In the Data Environment Designer, select the table or view.
  2. From the DataEnvironment menu, choose Remove.

Setting Relationships in the Data Environment Designer

If you add tables to the Data Environment Designer that have persistent relationships set in a database, the relationships are automatically added in the data environment. If the tables don't have persistent relationships, you can still relate them in the Data Environment Designer.

To set relationships in the Data Environment Designer

  • Drag a field from the primary table onto the matching index tag in the related table.

You can also drag a field from the primary table to a field in the related table. If there is no index tag in the related table corresponding to the field in the primary table, you're prompted to create the index tag.

Editing Relationships in the Data Environment Designer

When you set a relation in the Data Environment Designer, a line between the tables indicates the relationship.

To edit the properties of the relation

  • In the Properties window, select the relation from the Object box.

The properties of the relation correspond to clauses and keywords in the SET RELATION and SET SKIP commands.

The RelationalExpr property is set by default to the name of the primary key field in the primary table. If the related table is indexed on an expression, you need to set the RelationalExpr property to this expression. For example, if the related table is indexed on UPPER(cust_id), you need to set RelationalExpr to UPPER(cust_id).

If the relation is not a one-to-many relationship, set the OneToMany property to false (.F.). This corresponds to using the SET RELATION command without issuing SET SKIP.

Setting the OneToMany property of a relation to true (.T.) corresponds to issuing the SET SKIP command. When you skip through the parent table, the record pointer remains on the same parent record until the record pointer moves through all related records in the child table.

Note   If you want a one-to-many relationship in the form, set the OneToMany property to true (.T.), even if a persistent one-to-many relationship has been established in a database.

See Also

Creating a New Form | Creation of Single- and Multiple-Document Interfaces | Creating Forms | Specifying a Form Type | Displaying a Child Form Inside a Top-Level Form | Add Table or View | Properties Window | Designing Forms

Show:
© 2014 Microsoft