Main Menu
Knowledge Base
Product Registration
Log an Incident
Request a Feature
Search Incidents/Bug Reports


Search KB

Please note: In an effort to better serve you, we are in the process of restructuring DevCenter. In the process, we have moved many items that you may be used to finding in DevCenter over to the Main Site. If you are having trouble locating something, please try looking at the following places:

Knowledge Base Article: KB09995

HOWTO:Bind data from an Access database to a WebGrid using using declarative programming with the AccessDataSource


The information in this article applies to:
UltraWebGrid (v5.3.20053, 6.1.20061, 6.2.20062)
  Article Created: 
8/11/2006

Last Updated:
8/11/2006

Article Type
How To
  
Page Options
Average Rating:
7 out of 10

Rate this page
Print this page
E-mail this page
Add to Favorites

Summary

With the introduction of DataSource controls in ASP.Net 2.0, a developer can connect the presentation layer directly data taken from an Access database by using an AccessDataSource control. Our controls have complete built in support for this new feature of version 2.0 of the .NET Framework, and thus you can use them to connect to an Access database without having to write a single line of code.

Additional Information

While it is a powerful and easy-to-use object, the AccessDataSource is not without limitations. With respect to the WebGrid, the most important limitation is that the AccessDataSource does not provide hierarchical data. It represents only a single table of data, and there is currently no way to relate multiple AccessDataSource objects to each other.

Step-By-Step Example

The steps below demonstrate how to configure a WebGrid to load data from an AccessDataSource. The samples linked to this article illustrate what the end result should look like, and include the Access database file "People.mdb" used in this example.

1. Drop a WebGrid, an AccessDataSource control, and a button to a page in a new ASP.NET website.
2. Configure the AccessDataSource control.

    a. Open the DataSource configuration for the AccessDataSource control.
    b. Click the "Browse" button to select a file.

Choose Database Screenshot – Click Browse

    c. Choose the Access database file (extension .mdb) you want to use, and click "OK." Note that the file must exist within the structure of your website.

Select Microsoft Access Database Screenshot

    d. On the main wizard, you should see the filename in the text area. Click "Next."

Choose Database Screenshot – Click Next

    e. On this screen, choose the table and columns you want to show in the WebGrid. For this example, we want to select all columns from the "Person" table. Once the columns are selected, click "Advanced" to configure the automated SQL statements.

Configure Select Statement Screenshot – Click Advanced

    f. Check the "Generate INSERT, UPDATE, and DELETE statements" checkbox, and click "OK."

Advanced SQL Generation Options Screenshot

    g. Click "Next."

Configure Select Statement Screenshot – Click Next

    h. Click “Test Query” to make sure that the connection works.

Test Query Screenshot

    h. Click "Finish."

3. Configure the grid to attach to the datasource control by setting the following properties.
    a. UltraWebGrid1.DataSourceID = AccessDataSource1 (NOTE: If doing this in code, use AccessDataSource1.UniqueID instead)
    b. UltraWebGrid1.DisplayLayout.AllowUpdateDefault = Yes (this should be the value set by the default preset)
    c. UltraWebGrid1.DisplayLayout.AllowAddNewDefault = Yes
    d. UltraWebGrid1.DataKeyField = "ID"
    e. UltraWebGrid1.Bands[0].DataKeyField = "ID"

Now, when you run the application, you can insert, update, and delete rows within the WebGrid. Clicking on the button will cause a postback; this causes the WebGrid to notify the AccessDataSource of the changes, which will commit all these changes to the database automatically.

Related Articles

HOWTO: Bind a custom object to a WebGrid using declarative programming with the ObjectDataSource (KB09968)

HOWTO: Bind data from SQL Server to a WebGrid using declarative programming with the SqlDataSource (KB09994)

Samples

webgrid_accessdatasource_2006v2_cs.zip
 Demonstrates how to bind data from an Access database to a WebGrid using an AccessDataSource


webgrid_accessdatasource_2006v2_vb.zip
 Demonstrates how to bind data from an Access database to a WebGrid using an AccessDataSource



How would you rate the quality of this content?
Poor -----------------------------------------> Outstanding

Tell us why you rated the content this way. (optional)