Introduction
A common design pattern in business applications is to separate the presentation layer, business logic layer and the data access layer. The data access layer encapsulates the underlying SQL statements for data manipulation. You can implement the components of this layer using strongly typed DataSet. The business logic layer enables specifying business entities, business rules and workflow associated to the underlying logic of your business. You can implement the components of this layer using strongly typed DataSet as well as custom business objects by defining classes in any language supported by .NET such as C#. The presentation layer enable display the data associated to business entities as well as control the interaction from the end user and the business application. This model results in a three-layer application architecture.
In this article, we're going to see how to illustrate the main principles, design patterns and techniques to implement a three-layer enterprise application using Visual Studio 2005 and SQL Server 2005. The business scenario is basically that AdventureWorks Inc. needs a portal site to manage information about its products anywhere within its corporate network. We're going to use the AdventureWorks database shipped with SQL Server 2005 and the table Production.Product.
Developing the solution
The first step is two create a solution with two projects in Visual Studio 2005: a Web Site project and a Class Library project. The Class Library project comprises of the Data Access components and Business Logic components representing the Product business entity. The Web Site project is the portal which enables managing information about the products in AdventureWorks.
Add a DataSet item to the Class Library project and name it DSProduct.xsd. Next add a TableAdapter to the DSProduct.xsd (see Figure 1). And finally compile the library.

Figure 1
Now let's configure the Optimistic Concurrency control by checking the field ModifiedDate to detect concurrency conflicts. Click on the ProductTableAdapter and go to the Properties window (see Figure 2).

Figure 2
Change the Insert, Update, Delete commands in order to support Optimistic Concurrency Control. The Insert command is shown in Listing 1, the Update command in Listing 2, and the Delete command in Listing 3.
INSERT INTO
Production.Product (Name, ProductNumber, MakeFlag, FinishedGoodsFlag, Color, SafetyStockLevel, ReorderPoint, StandardCost, ListPrice, Size, SizeUnitMeasureCode, WeightUnitMeasureCode, Weight, DaysToManufacture, ProductLine, Class, Style, ProductSubcategoryID, ProductModelID, SellStartDate, SellEndDate, DiscontinuedDate)VALUES (@Name,@ProductNumber,@MakeFlag,@FinishedGoodsFlag,@Color,@SafetyStockLevel,@ReorderPoint,
@StandardCost,@ListPrice,@Size,@SizeUnitMeasureCode,@WeightUnitMeasureCode,@Weight,@DaysToManufacture,
@ProductLine,@Class,@Style,@ProductSubcategoryID,@ProductModelID,@SellStartDate,@SellEndDate,@DiscontinuedDate)
Listing 1
UPDATE Production.Product
SET Name = @Name, ProductNumber = @ProductNumber, MakeFlag = @MakeFlag,
FinishedGoodsFlag = @FinishedGoodsFlag, Color = @Color, SafetyStockLevel = @SafetyStockLevel,
ReorderPoint = @ReorderPoint, StandardCost = @StandardCost, ListPrice = @ListPrice,
Size = @Size, SizeUnitMeasureCode = @SizeUnitMeasureCode, WeightUnitMeasureCode = @WeightUnitMeasureCode,
Weight = @Weight, DaysToManufacture = @DaysToManufacture, ProductLine = @ProductLine,
Class = @Class, Style = @Style, ProductSubcategoryID = @ProductSubcategoryID, ProductModelID = @ProductModelID,
SellStartDate = @SellStartDate, SellEndDate = @SellEndDate, DiscontinuedDate = @DiscontinuedDate
WHERE (ProductID = @ProductID) AND (ModifiedDate = @ModifiedDate)
Listing 2
DELETE FROM Production.Product
WHERE (ProductID = @ProductID) AND (ModifiedDate = @ModifiedDate)
Listing 3
Now let's add a page to the Web Site Project and name it DataBindingPage.aspx as well as add a reference to the Class Library project in order to use the Product business entity.
Drag and drop a GridView control onto the DataBindingPage.aspx Web page and configure the data binding support. Controls that support data binding expose a property named DataSource and a method called DataBind. When the page is loaded, the GridView is initialized to some collection of data such as DataSet and then the method DataBind is invoked. At this point, the data are read from the underlying data source and are rendered in order to generate the HTML code for the browser. The code-bind implementing this logic is specified in Listing 4.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WSTest.BizObjects;
using WSTest.BizObjects.DSProductTableAdapters;
public partial class DataBindingPage : System.Web.UI.Page
{
protected void ptdDataBind()
{
DSProduct dsProduct = new DSProduct();
ProductTableAdapter taProduct = new ProductTableAdapter();
taProduct.Fill(dsProduct.Product);
this.GridView1.DataSource = dsProduct;






Manu sharmaPosted Apr 23, 2009, 7:18 AM
sir i m devloping a web site estudyzone.com.its a plateform where learner & trainer communative & share knowledge. i want to add a feature chatting.but have no knoledge for developing a chatting program. so plz send code for devloping chatting program.... thanks& regard Himanshu