RAD Studio for Microsoft .NET
ContentsIndex
PreviousUpNext
Building an ASP.NET Database Application

The following procedure describes the minimum number of steps required to build a simple ASP.NET database application such as BDP.NET. After generating the required connection objects, the project displays data in a DataGrid. 

For a more detailed database sample using other database technologies for ASP.NET 2.0, see Building an ASP.NET Application with Database Controls 1

BDP.NET includes component designers to facilitate the creation of database applications. Instead of dropping individual components on a designer, configuring each in turn, use BDP.NET designers to rapidly create and configure database components. The following procedure demonstrates the major components of ASP.NET, ADO.NET, and BDP.NET at work. 

Building an ASP.NET application with database components consists of four major steps:

  1. Create an ASP.NET project.
  2. Configure database connection components and a data source.
  3. Add a DataBind call.
  4. Connect a DataGrid to the connection components.
Tip: For testing purposes, use the employee.gdb database included with Interbase, if included with your version of the product.

To create an ASP.NET project

  1. Choose FileNewASP.NET Web Application. The New ASP.NET Web Application dialog appears.
  2. In the Name field, enter the name of your project.
  3. In the Location field, use the default or enter the project path.

To change Web server settings (optional)

  1. In the New ASP.NET Web Application dialog, click View Server Options The dialog expands to show additional server options.
  2. Set the various read and write attributes of the project as needed or accept the defaults.
    Tip: In most cases, the default settings will suffice.
  3. Click OK. The Web Forms Designer appears.

To configure data components

  1. Drag and drop a BdpDataAdapter component onto the Designer. If necessary, select BdpDataAdapter.
  2. In Object Inspector, select Configure Data Adapter. The Data Adapter Configuration dialog appears.
  3. If necessary, select the Command tab. From the Connection drop-down, select New Connection.
  4. The Borland Data Provider: Connections Editor dialog appears.
    Tip: Alternatively, use Data Explorer to drag and drop a table on to the Designer surface. Data Explorer sets the connection string automatically.

To set up a connection

  1. In Borland Data Provider: Connections Editor, select the appropriate item from the Connections list.
  2. In Connection Settings, enter the Database path.
    Note: If referring to a database on the local disk, prepend the path with localhost:
    . If using Interbase, for example, you would enter the path to your Interbase database: localhost:C:\Program Files\Borland\Interbase\Examples\Database\employee.gdb (or whatever the actual path might be for your system).
  3. Complete the UserName and Password fields for the database as needed.
  4. Click Test to confirm the connection. A dialog appears confirming the status of the connection.
  5. Click OK to return to the Borland Data Provider: Connections Editor dialog.
  6. Click OK to return to the Data Adapter Configuration dialog. In the Command tab, the areas for Tables and Columns are updated with information from your connection.

To set a command

  1. In the Select area, enter an SQL command.
    Tip: For Interbase's employee.gdb database, you might enter select * from SALES
    , as an example.
  2. Click the Preview Data tab.
  3. Click Refresh. Column and row data appear.
  4. Click the DataSet tab.
  5. Confirm that New DataSet is selected.
  6. Click OK. New components for DataSet and BdpConnection appear on the Designer.
  7. Select BdpDataAdapter component.
  8. In Object Inspector, select the Active property drop-down and set the value to True.

To connect a DataGrid to a DataSet

  1. Drag and drop a DataGrid web control onto the Designer. If necessary, select DataGrid.
  2. In Object Inspector, select the DataSource property drop-down. Select the DataSet component that you generated previously (the default is DataSet1).
  3. In Object Inspector, select the DataMember property drop-down. Select the appropriate table. The DataGrid displays data from the DataSet.

To add a DataBind call

  1. Use the Object Inspector drop-down to select the Web Form (WebForm1 is the default).
  2. In Object Inspector, select the Events tab.
  3. Set the Load event to Page_Load.
  4. In Object Inspector, double-click Page_Load. The code-behind Designer appears, cursor in place between event handler brackets.
  5. Code the DataBind call:

this.dataGrid1.DataBind();

 

Self.dataGrid1.DataBind();

Note: If you are using data aware controls, for instance from a third-party provider, you may not need to code the DataBind call.
  1. Choose RunRun. The application compiles and the HTTP server displays a Web Form with the datagrid.
While presenting a minimum number of steps required to build a database project, the preceding procedure demonstrates the major components of the ASP.NET, ADO.NET, and BDP.NET architectures at work, including: providers, datasets, and adapters. The adapter connects to the physical data source via a provider, sending a command that will read data from the data source and populate a dataset. Once populated, a datagrid displays data from the dataset. 

Once created, use other BDP.NET designers to modify and maintain the components of your project.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!