Consolidating the Data-Access Code

Most ASP.NET projects have more than one page that needs to use the data model. A common approach to avoiding duplicating the same code is to consolidate the code that deals with the data model into one or more common classes, which are then used by all of the page classes. We will follow this approach before extending the example web application to create, modify, and delete data. Listing 8-9 shows this class, called DataAccess, which contains methods that perform the functionality from the examples so far.

Listing 8-9. The DataAccess class

using System.Collections.Generic; using System.Linq; using System; namespace DataApp {     public static class DataAccess {         ///////////////////////////////

Get Applied ASP.NET 4 in Context now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.