Using the DataAdapter Object

The DataAdapter acts as the bridge between an in-memory database table and a physical database table. You use the DataAdapter to retrieve data from a database and populate a DataTable. You also use a DataAdapter to push changes that you have made to a DataTable back to the physical database.

The component in Listing 19.25 illustrates how you can use a SqlDataAdapter to populate a DataTable.

Listing 19.25. App_Code\Movie8.cs

images

The page in Listing 19.26 contains a GridView that is bound to an ObjectDataSource that represents the component in Listing 19.25 (see Figure 19.12).

Figure 19.12. Displaying data with a DataAdapter ...

Get ASP.NET 4 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.