Configure a data source by using a data bound control

The Data Source Configuration Wizard in Microsoft Expression Web enables you to display data from a database by using an ASP.NET control that supports data binding. For a list of ASP.NET controls that support data binding, see Databases.

Note

If you want to configure a data source by using a data source control, see Configure a data source by using a data source control. With Expression Web, you can connect to a variety of data sources, including Microsoft Office Access databases, databases that can be accessed by using OLE DB or ODBC protocols, ASP.NET SiteMapDataSource controls, and XML files.

Important

Microsoft Access databases (.mdb files) are less secure than Microsoft SQL Server databases. If possible, consider moving your data to a SQL database such as SQL Express. However, if you have to use an .mdb file as part of your web application, follow the guidelines in the "Microsoft Access Databases" section in Securing Data Access in the MSDN library.

This topic shows you how to insert an ASP.NET data control that displays content stored in a database. It then shows you how to connect to a database by using the Data Source Configuration Wizard.

Procedures

To configure a data source

  1. In your .aspx page, in Design view, from the Toolbox task pane, drag one of the data binding controls such as GridView onto the page.

  2. Right-click the control, and then click Show Common Control Tasks.

  3. In the Show Common Control Tasks window, from the Choose Data Source drop-down list, select New data source. If there is no drop-down list available in the Show Common Control Tasks window, click Choose Data Source.

  4. In the Data Source Configuration Wizard, on the Choose a Data Source Type page, click one of the following to specify the type of data source to which you want to connect:

    • Access Database   Connect to a database created with Microsoft Access.

    • **Database   **Connect to any SQL database supported by ADO.NET, such as Microsoft SQL Server, Oracle, or OLE DB.

      Note

      Select Database to bind the control to an ASP.NET connection in the Data Source Library.

    • **Site Map   **Connect to the site navigation tree for this application (requires a valid sitemap file at the application root).

    • **XML File   **Connect to an XML file.

      Note

      The value of the ID attribute for the data source control in the Specify an ID for the data source text box is automatically created by the Data Source Configuration Wizard.

  5. Now that you have selected the type of data source to which you want to connect, you are ready to connect the data source to the ASP.NET control. For more information, locate the type of data that you are using in the following chart:

    If you specified

    See the section

    An Access Database source

    To configure an Access Databasee

    A Database source

    To configure a Database source

    A Site Map data source

    To configure a Site Map data source

    An XML File source

    To configure an XML File source

To configure an Access Database

  1. On the Choose a Database page, in the Microsoft Access data file box, specify the relative path of the Microsoft Access database file, and then click Next.

  2. In the Configure the Select Statement dialog box, do one of the following:

    • Click Specify a custom SQL statement or stored procedure to build a custom SQL statement, or select a stored procedure if you have one configured for your website.

    • Click Specify columns from a table or view, and then select the table name and the columns of data to obtain. You can further define your SELECT statement using the WHERE, ORDER BY, and Advanced buttons. The SELECT statement that you build is visible in the SELECT statement area.

  3. Click Next.

  4. On the Test Query page, click Test Query to verify that your query returns the data that you want, and then click Finish.

To configure a Database source

  1. On the Choose Your Data Connection page, do one of the following:

    • In the Which data connection should your application use to connect to the database dialog box, select an ASP.NET connection that you have configured in the Data Source Library task pane.

    • Click New Connection to create a new database connection. In the Choose Data Source Wizard, you can select a data source type and provider, and build a connection string.

  2. Click Next.

  3. If you created a new database connection string, on the Save the Connection String to the Application Configuration File page, check the Yes, save this connection as check box, and then provide a connection string name to save the connection string in the web.config file. Click Next.

    Note

    To modify the connection string after it has been saved, on the Task Panes menu, click Data Source Library. In the Data Source Library task pane, under ASP.NET Connections, right-click the data source that you want to modify and click Properties. In the Connection Properties dialog box, click Advanced.

  4. On the Define Custom Statements or Stored Procedures page, do one of the following:

    • If there are stored procedures in your database and you want to use one as your data source, click Stored procedure and select the procedure from the drop-down list box.

    • Click SQL statement and the tab for the type of statement you want to create: SELECT, UPDATE, INSERT, or DELETE. Type your SQL statement in the Edit dialog box or click Query Builder for help in constructing your SQL statement.

  5. Click Next.

  6. On the Test Query page, click Test Query to verify that your query returns the data that you want, and then click Finish.

To configure a Site Map data source

  • If you specified a Site Map data source, Expression Web creates an ASP.NET SiteMapDataSource control and completes the wizard.

To configure an XML File source

  1. In the Configure Data Source dialog box, under Data file, click Browse.

    Note

    Save the web page before selecting the XML data source.

  2. In the Select XML File dialog box, locate your XML file and click Open.

  3. Optional: In the Transform file dialog box, specify the location of the XSLT file.

  4. Optional: In the XPath Expression dialog box, type the XPath expression. An XPath expression uses the following format, where any number of child element levels can be specified:

    /rootElementName/childElementName
    

    Note

    If you specify an XPath expression, only the data at the level of the specified element and below is returned.

See also

Concepts

ASP.NET data controls

Data Source Details task pane

Data Source Library task pane

Databases overview