Create a DAL for an ObjectDataSource
Web Application Vs Web Site
Web Site Techniques
Create a DAL for an ODS
Adventures in .net Paging
Add Paging to a DataList
SQL Server Primer
Lower & Upper
RowNumber & Rank
Name Your Site
Syndicate With RSS
Web Design - Get a Spine!
Security: What Hackers Do
Intro To PHP
CGI: What & How?
Start a Traffic Virus
Create A DataAcessLayer for an ObjectDataSource
ASP.Net tutorial ©2012
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
and install the Northwind database.
In Solution Explorer, right click on the App_Code folder and select "Add New Item". Select "Add Dataset".
From Server Explorer, drag and drop a table to the Dataset Designer.
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.
Right-click on the table adapter and select "Add Query".
Select a Command Type.
Select one of the Query Types. In this example, "Select which returns rows" is selected.
Enter a SQL Statement.
Choose a Method to Generate and assign a Method Name.
You should receive a message that table adapter was configured correctly. Select Finish.
- All rights reserved