Create a DAL for an ObjectDataSource

Create A DataAcessLayer for an ObjectDataSource
ASP.Net tutorial ©2012
Next Page           
An ASP.Net ObjectDataSource can be easily wired to a Data Access Layer (DAL) in Visual Studio.  Best practices dictates that the User Interface, Business Logic, and Data Access functionality be separated into different tiers.  
While a DAL does not provide a business layer, it does separate data access functionality from the user interface.
C# Sample Code
Note: These dialogs are from a Web Application.  The dialogs may differ in Web Projects or WinForms
Download and install the Northwind database.
1.  In Solution Explorer, right click on the App_Code folder and select "Add New Item". Select "Add Dataset".

2.  From Server Explorer, drag and drop a table to the Dataset Designer.
3.  The Dataset Designer will now display the data table. A web.config connection string was automatically created. There should be a single web connection string. If a connection string is already configured, right-click on the data table TableAdapter and in the context menu select Properties. Update Connection to point to the previously setup connection. You should also remove the newly added connection string from your web.config to keep it nice and tidy.  
4.  Right-click on the table adapter and select "Add Query".  
5.  Select a Command Type.  
6.  Select one of the Query Types. In this example, "Select which returns rows" is selected.  
7.  Enter a SQL Statement.  
8.  Choose a Method to Generate and assign a Method Name.  
9.  You should receive a message that table adapter was configured correctly. Select Finish.  
Next Page           
 Contact Us      ©2015 - All rights reserved
Powered by