Click here to Skip to main content
15,886,578 members
Articles / Web Development / ASP.NET

Designing and implementing a versatile data access tier for an ASP.NET application

Rate me:
Please Sign up or sign in to vote.
4.63/5 (45 votes)
3 Feb 200328 min read 384.5K   3.8K   242  
In this article, we will drill down deeper in to the design of a n-tier architecture and our focus will be on the data access tier (DAT)
/* Sql scripts for DAPrototype*/
USE Northwind
GO
/*  Used in DAPrototype*/
CREATE PROCEDURE  SPSelCustomers
(
  @CustomerID  varchar(5)
)
AS
SELECT  
  C.CustomerID,C.CompanyName,C.Address,C.City 
FROM   Customers C
WHERE  C.CustomerID LIKE @CustomerID + '%'
GO

/*  Used in DAPrototype*/
CREATE PROCEDURE SPSelOrders
(
   @CustomerID nchar(5)
)
AS
SELECT  O.OrderID,O.CustomerID, O.OrderDate 
FROM
  Orders O
WHERE O.CustomerID =  @CustomerID
ORDER BY O.OrderDate  DESC
GO
/*  Used in DAPrototype*/
CREATE PROCEDURE    SPSelOrderDetail
(
   @OrderID int
)
AS
SELECT   OD.ProductID , OD.UnitPrice,OD.Quantity, P.ProductName
FROM [Order Details]   OD INNER JOIN Products  P
 ON  OD.ProductID =  P.ProductID
WHERE OD.ORDERID =@OrderID
GO

/*  Used in DAPrototype*/
CREATE PROCEDURE SPUpOrderDetail 
(
@OrderID int,
@ProductID int,
@Quantity int

)
AS
UPDATE [Order Details]
SET Quantity =@Quantity
WHERE ProductID=@ProductID AND OrderID=@OrderID
GO
/* Used in DAPrototype */
CREATE PROCEDURE SPDelOrders
(
@OrderID int
)
 AS

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE 
BEGIN TRANSACTION

DELETE [Order Details]  WHERE OrderID = @OrderID 
DELETE Orders WHERE OrderID = @OrderID

IF @@error  > 0
ROLLBACK TRANSACTION
ELSE
COMMIT TRANSACTION
GO


/* Used in DAPrototype*/
CREATE PROCEDURE SPDelOrdersDemo
(
@OrderID int
)
 AS
DELETE Orders  WHERE  OrderID = @OrderID
GO

/*  Used in DAPrototype*/
CREATE PROCEDURE SPDelODDemo
(
@OrderID int
)
 AS
DELETE [Order Details]   WHERE OrderID  = @OrderID
GO

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Switzerland Switzerland
Paul Abraham is a software developer who designs and develops multi-shop systems.

He has received his M.Sc in Mathematics and Computer Science from the FernUniversität Hagen(http://www.fernuni-hagen.de Germany) and his main interests are neural networks and bayesian statistics He lives in Rosenheim (South Germany http://www.rosenheim.de). You can reach him at admin@paul-abraham.com.

Comments and Discussions