Click the link above to download Visual Basic source code in a Visual Studio 2005 solution which demonstrates how to use Visual Studio to create a basic component for a data access layer (DAL) for Microsoft Access databases.
Get Dot Net Code is a web site full of free and pay for use Visual Basic source code for Visual Basic programmers.
Data Access Layer For Microsoft Access Databases
Part 2
Source Code: DalForMSAccessPart2.zip
This is the second part of a tutorial article which demonstrates how to create a data access layer (DAL) with .NET 2.0, ADO.NET 2.0, Visual Studio 2005, and Visual Basic 2005.
A basic data access layer component (DAL) for Microsoft Access databases was created in part one.
In part two the DAL component will be extended and then used for the first time by a Windows Forms application.
Before the article discusses how to extended the DAL component it will first discuss the DataSets created in part one of the article.
Understanding the DataService Project DataSets
In part one, two DataSets were added to the DataService project; the AjaxDataSet and the NorthwindDataSet. A DataSet was added each time a DataSource was added to the DataService project. One DataSource was added to the DataService project for each Microsoft Access database the DataService DAL component will access.
Part of the process of adding a DataSource to a project is selecting one or more tables from a database. For example, in part one the
Selecting the Customer table from the
At the same time as the DataTables were automatically added to the DataSet, default TableAdapters were created and associated with the DataTables.
TableAdapters
A TableAdapter named 'CustomerTableAdapter' was added and associated with the Customer DataTable. A TableAdapter named 'OrdersTableAdapter' was added and associated with the Orders DataTable.
TableAdapters provide communication between an application and a database. A TableAdapter connects to a database, executes queries or stored procedures, and either returns a new data table populated with the returned data or fills an existing DataTable with the returned data. TableAdapters are also used to send updated data from your application back to the database.
Users of previous versions of Visual Studio can think of a TableAdapter as a DataAdapter with a built-in connection object and the ability to contain multiple queries. Each query added to a TableAdapter is exposed as a public method that is simply called like any other method or function on an object.
TableAdapter Queries
When the AjaxDataSet and the NorthwindDataSet were created in part one of this article, an initial query was automatically added to every TableAdapter. For example, an initial query was automatically added to the CustomerTableAdapter and the OrdersTableAdapter in the AjaxDataSet:
评论