正文

VB2005如何实现Access数据库的数据访问层22006-12-02 18:20:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/iamben250/21179.html

分享到:

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 Ajax database Customer and Orders tables were selected.

Selecting the Customer table from the Ajax database automatically added a Customer DataTable to the Ajax DataSet.  Selecting the Orders table from the Ajax database automatically added an Orders DataTable to the Ajax Dataset.  In the Solution Explorer double-click the AjaxDataSet in the DataService project to see the two DataTables that were created.

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:


 

阅读(3656) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册