The data environment is a repository in your Microsoft® Visual InterDev™ Web project for the information required in server script to connect and manipulate data in databases. It provides a standard interface for creating re-usable data-related objects and for placing them on Web pages.
Note The data environment is available on the server. If you are designing a Web application that uses client access to data (using Microsoft® Internet Explorer 4.0 DHTML), the data environment is available at design time, but not used at run time.
The data environment also provides an object you can reference in script, allowing you to access and manage database objects such as tables, views, stored procedures, and SQL commands programmatically. It provides an easy-to-use wrapper around ActiveX Data Objects (ADO), making these objects more accessible and easier to work with in Visual InterDev.
To understand the data environment, you must understand these concepts:
The primary component of the data environment is a data connection, which includes the information required to connect to one database with a specific user name. For example, your data environment might include a connection that links your application to the Pubs database on a Microsoft® SQL Server® under the user names Admin (at design time) and Guest (at run time). If your application requires access to multiple databases, you can add multiple data connections to your data environment.
Within each data connection, you can add one or more data commands (command objects), which define a set of data to work with. Command objects can reference a database object such as a table, query, view, synonym, stored procedure, or SQL statement. For example, you might create a command object that references the Authors table so you can display the contents of that table on a Web page. You could also define additional command objects to reference queries and stored procedures you can call to display and update data in other tables.
A Web project showing the data environment and data commands
Command objects are accessible to any page in your application. They therefore become reusable objects. If the underlying database changes, you can make a single change to the command object, and all Web pages that reference the command object will continue to work properly.
Each command object is a node that contains additional information relating to that command object. For example, a command object that references a table contains a list of columns in that table. A command object that references a stored procedure can contain a list of the columns returned by the procedure, or it can contain a list of the procedure's parameters. For information on adding Command objects, see Getting Records and Recordset Properties Dialog Box.
Visual InterDev creates a data environment for your project the first time you define a data connection. As soon as you add the connection, Visual InterDev creates the DataEnvironment folder and adds it as a node under the Global.asa file. The data connection you added is displayed in the DataEnvironment node.
As you create additional data connections, they are added to the DataEnvironment node.
Note You can only have one DataEnvironment node (and one data environment) in a Visual InterDev project. For more information on adding data connections, see Connecting to a Database.
An important feature of the data environment is that you can drag objects to and from it to simplify the process of adding database access to your application. To create new commands, you can drag database objects from the Data View window to the data environment. In addition, you can create data-bound controls on a page by dragging commands and database fields from the data environment to your page.
The following table summarizes how you can use drag and drop with the data environment.
Drag | From | Drop on | To |
Database object | Data View | Connection in data environment | Create a command object for the database object you dragged. For example, dragging a table creates a command object whose Database Object type is table. |
Command object or Field object | Data environment | Web page | Create a data-bound control. |
Database object | Data View | Web page | Not allowed. Drag objects from the data environment instead. |
For details about using data-bound controls, see the Recordset design-time control and Viewing Data.
The data environment supports its own object model, which you can use when writing script to manipulate the data you want to display on your Web page. The data environment object model is based on the ActiveX Data Objects (ADO) object model, but is simpler to use.
In ADO, the main objects in the data environment object model are the Connection object, Command object, Recordset object, Field objects, and Parameter objects. Each of these ADO objects has its own properties and methods.
The data environment abstracts this object model to make it simpler to use. The data environment itself is an object that can be used in script and that contains these ADO objects. Within the data environment object, command objects are exposed as methods in script. You can call a command method to execute it and return the recordset referenced by the command or to execute its SQL command or stored procedure.
Each of the data environment objects also has properties you can set in the property page for that object or directly in script. For more information on the data environment object model and the properties for each object, see Executing Database Commands.