Click here to Skip to main content
15,895,746 members
Articles / Desktop Programming / Windows Forms

Create a Business Logic Layer, Data Access Layer classes, and Stored Procedure scripts from a database table

Rate me:
Please Sign up or sign in to vote.
4.88/5 (30 votes)
4 Jun 2010CPOL2 min read 177.1K   10.3K   87  
Create a Business Logic Layer, Data Access Layer classes, and Stored Procedure scripts from a database table.
--------- SP_Employee_Select


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SP_Employee_Select]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[SP_Employee_Select]
Go

SET QUOTED_IDENTIFIER OFF 
Go
SET ANSI_NULLS OFF
Go

CREATE PROCEDURE SP_Employee_Select


@EmployeeID int,
@EmployeeName varchar(50),
@EmployeeType varchar(50)

AS

Select 

EmployeeID,
EmployeeName,
EmployeeType

from Employee

where 
( @EmployeeID is null or @EmployeeID = EmployeeID ) and
( @EmployeeName is null or @EmployeeName = EmployeeName ) and
 @IsActive = IsActive

Go


SET QUOTED_IDENTIFIER OFF 
Go
SET ANSI_NULLS OFF
Go





--------- SP_Employee_Delete


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SP_Employee_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[SP_Employee_Delete]
Go

SET QUOTED_IDENTIFIER OFF 
Go
SET ANSI_NULLS OFF
Go

CREATE PROCEDURE SP_Employee_Delete

@EmployeeID int

AS

Update 
Employee

set IsActive = 0

where EmployeeID=@EmployeeID

Go


SET QUOTED_IDENTIFIER OFF 
Go
SET ANSI_NULLS OFF
Go





--------- SP_Employee_Insert


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SP_Employee_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[SP_Employee_Insert]
Go

SET QUOTED_IDENTIFIER OFF 
Go
SET ANSI_NULLS OFF
Go

CREATE PROCEDURE SP_Employee_Insert


@EmployeeName varchar(50)

AS

Insert into Employee
(
EmployeeName,
EmployeeType
)
values
(
@EmployeeName,
1
)

Go


SET QUOTED_IDENTIFIER OFF 
Go
SET ANSI_NULLS OFF
Go





--------- SP_Employee_Update


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SP_Employee_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[SP_Employee_Update]
Go

SET QUOTED_IDENTIFIER OFF 
Go
SET ANSI_NULLS OFF
Go

CREATE PROCEDURE SP_Employee_Update


@EmployeeID    int,
@EmployeeName    varchar(50)

AS

Update Employee

Set
	
	EmployeeName = @EmployeeName,
	 IsActive = 1
Where

EmployeeID = @EmployeeID

Go


SET QUOTED_IDENTIFIER OFF 
Go
SET ANSI_NULLS OFF
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions