As a web developer, we deal with mountainous quantities of data.
To handle this, databases are created to store the data, retrieve and modify it. Web pages are built in conjunction to collect and summarise it.
This is done by creating what we call a Data Access Layer (DAL).
How do we create a Data Access Layer?
1. Create a website or application
2. Set up database
3. As the application or web site is created, add a reference to the database in Visual Studio’s Server Explorer.
4. Go to the Server Explorer in Visual Studio, right-click on the Data Connections node, and choose Add Connection.
5. The presentation layer of code should make a ‘call’ into the DAL for all data requests.
6. Such methods when called for will connect to the database, issue the query and then return the results.
7. The methods simply return a DataSet or DataReader that will be populated by the database.
Examples:
In your DAL, some methods can be:
- GetProducts(), returning all product information from the database
- GetProductsByCategoryID(categoryID), which returns all products that are associated with a category ID.
8. Developers can create their own custom objects or use Typed DataSets. E.g. Object A (of data) is implemented by the developer as a class. Object A has properties reflecting the columns of the underlying database that Object A contains.
The rule of thumb is that all code specific to the underlying data source should be located on the DAL.
Further information on creating a DAL in C# on Visual Studio visit: