Make your own free website on Tripod.com

Online Resume - VB.Net - C#.Net SQL Server Developer

ADO.Net / DataAccess Example

Home | Tim Levito Resume | C# .Net Multi-Tiered Application Example | DataBase / Stored Proc Example | ADO.Net / DataAccess Example | WinForm / Business Layer Example | ASP.Net / Javascript / Html Web Example | Contact Me

This section will take a look at the Data Access Layer which is written in C# and ADO.net for a safe and reliable connection between the database, its Stored Procedures, and our n-tiered .Net Application.

The Data Access Layer sits directly on the Database and is responsible for securely and efficiently accessing the proprietary data source for the data needs of our application.

dataaccess1.gif

The Data Access layer is similar to other classes in the sense that it resides in a particular Namespace and contains several methods to achieve the purposes of the calling members.

 

This class contains methods for the primary purpose of creating a connection to, communicating requests, and receiving any output generated by the database from these requests.

 

The primary caller to this class is the business layer. In the business layer the data is validated for correct type, format, and adherence to the business organizations rules. By using this multi-tiered approach, there is an additional layer of protection to the database and when changes need to be made, the code is organized and easy to navigate.

 

For the purposes of this application the Data Access class is stateless. This basically means that each transaction it processes is separate from the last and that no state information is kept in the properties and fields of the class.

 

So far in this Example we have been looking at the Add Juvenile Member Transaction and you can see the method signature code displayed below.

dataaccess2.gif

 

The method being called is the "AddMember" method and you can see in the code it is overloaded to accept two different Types of parameters.

 

The .Net framework and C# chooses the appropriate method based on the type of parameter passed. In this case, it's a Juvenile Member. 

dataaccess3.gif

In this Example, we are using ADO.Net to make a call to a Stored Procedure on the Database. There are several techniques for communicating with the Database through ADO.Net.

 

You can see from the comments in this example the steps we are taking to execute the desired Stored Procedure. This technique is a very controlled method and is considered to be manually controlling the execution behavior between C# code and the DataBase.

 

It's important to note the use of the Using { } Blocks for the efficient cleanup of the unmanaged resources in the method. By leaving unmanaged code open without the garbage collection services provided in the CLR, your application would be susceptible to loss of resources often called a memory leak. 

 

In the next Example, you can see how the data is controlled between the Business Layer and the Windows Form.

To Discuss a Current Project Opportunity further please send me an Email with your contact information and a good time to reach you to TLevito@yahoo.com