Click here to Skip to main content
15,867,568 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 175.8K   10.3K   87   28
Create a Business Logic Layer, Data Access Layer classes, and Stored Procedure scripts from a database table.

Introduction

One of the most tedious parts of developing database-driven applications is coding the classes for your database objects. Especially in a situation when you are dealing with a database containing a large number of tables, or tables with many columns. Today, the application development process has vastly expanded so it is better to use sub applications to generate code dynamically / automatically. I developed this application to reduce burden on software developers and provide them some relief. As a software developer, I can understand very well that programming is a tough job so they need some rest.

Key features

The application is designed to create:

  1. Business Logic Layer class
  2. Data Access Layer class
  3. SQL Database Stored Procedure script

Key benefits

  1. Reduce development time.
  2. Reduce development cost.
  3. Follow standard coding techniques and application architecture.
  4. Fully commented code so any one can easily modify it according to their needs.

How to use this application

In order to use this application, you must know the computer name/ IP address and the login information for connecting to a SQL Server database.

NotConnected.JPG

After successful login, you can go to another tab "Create Class and Stored Procedure". Select a particular database and check the tables to create the Stored Procedure and classes. Click on the Create button to create Stored Procedures and classes.

All classes and Stored Procedure scripts reside in the bin folder.

Connected.JPG

Example

As a very simple example, suppose we have the table name Employee.

DBTable.JPG

Create Business Logic Layer class

The Business Logic Layer class contains the namespaces, default constructor, private fields, and public properties with getters and setters and all the methods (Select, Insert, Delete, and Update) required for connecting the Database Access Layer. For every database table, it creates a class with the same name as the table name and concatenates it with controller. This example application will create a class with the name clsEmployeeController. It also creates properties with the name same as the table attributes.

BusinessLayer.JPG

Create Data Access Layer class

The Database Access Layer class contains the namespaces, default constructor, private fields, and public properties with getters and setters and all the methods (Select, Insert, Delete, and Update) required to directly deal with a database with Stored Procedures. For every database table, it creates a class with the same name as the table name and creates the properties with the same name as the table attributes. In this example, the application will create a class with the name clsEmployee.

DataBaseLayer.JPG

Create Stored Procedure script

It also creates a script of four Stored Procedures (Select, Insert, Delete, Update) in a Notepad file with the same name as the table name. You can simply copy and run it on the SQL Query Analyzer.

Points of Interest

I did not use any library in this application. It is a small application with big benefits.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
PraiseNice Work Pin
Member 125559232-Nov-17 20:25
Member 125559232-Nov-17 20:25 
GeneralFeedBack Pin
Rizwan ali15-Apr-15 23:25
Rizwan ali15-Apr-15 23:25 
SuggestionFeedback Pin
Jawad Shairf15-Feb-15 23:23
professionalJawad Shairf15-Feb-15 23:23 
QuestionHow to get this application....? Pin
Member 1084098014-Feb-15 21:15
Member 1084098014-Feb-15 21:15 
QuestionWhat does mean "Transaction"? Please help... Pin
Tavbi16-Jul-14 9:29
Tavbi16-Jul-14 9:29 
QuestionVariable and Properties Writting Pin
Shafiqur Rahman, Banladesh24-Jun-14 3:44
Shafiqur Rahman, Banladesh24-Jun-14 3:44 
QuestionGreat JOb! Pin
rajeshmoorthy17-Feb-14 17:02
rajeshmoorthy17-Feb-14 17:02 
QuestionWhere does it create the class? Pin
Ahmed Alaa El-Din19-Dec-13 9:35
Ahmed Alaa El-Din19-Dec-13 9:35 
QuestionComment Pin
Vicky19313-Jun-13 18:34
Vicky19313-Jun-13 18:34 
QuestionMicrosoft.ApplicationBlocks.Data Pin
Dipendra Paudel22-Aug-12 23:49
Dipendra Paudel22-Aug-12 23:49 
AnswerRe: Microsoft.ApplicationBlocks.Data Pin
aurinai17-Dec-12 6:15
aurinai17-Dec-12 6:15 
QuestionAny chance for a VB.NET version? Pin
GroBeMaus10-Apr-12 10:42
GroBeMaus10-Apr-12 10:42 
QuestionWhy are there two classes for each table? Pin
OpethManiac12-Jan-12 4:53
OpethManiac12-Jan-12 4:53 
AnswerRe: Why are there two classes for each table? Pin
GroBeMaus11-Apr-12 4:09
GroBeMaus11-Apr-12 4:09 
GeneralMy vote of 4 Pin
vanita tripathi17-Nov-11 19:35
vanita tripathi17-Nov-11 19:35 
GeneralMy vote of 5 Pin
Mahesh Gholap3-Jun-11 21:44
Mahesh Gholap3-Jun-11 21:44 
General[My vote of 1] Please tell me you used CodeDom Pin
Argyle4Ever4-Jun-10 5:31
Argyle4Ever4-Jun-10 5:31 
GeneralRe: [My vote of 1] Please tell me you used CodeDom Pin
Syeda Anila Nusrat4-Jun-10 8:07
Syeda Anila Nusrat4-Jun-10 8:07 
GeneralRe: [My vote of 1] Please tell me you used CodeDom Pin
Argyle4Ever4-Jun-10 9:35
Argyle4Ever4-Jun-10 9:35 
I have done it a few times using COdedom, its a very logical way of working and its well worth implementing it in CodeDom for the language flexibility you would get. esp if you are going to come up with a end product.

JC
GeneralRe: [My vote of 1] Please tell me you used CodeDom Pin
josto221-Jul-10 6:35
josto221-Jul-10 6:35 
Generalcombine with asp.net MVC Pin
zhuqil3-Jun-10 19:40
zhuqil3-Jun-10 19:40 
GeneralCode generation error [modified] Pin
ipadilla3-Jun-10 10:32
ipadilla3-Jun-10 10:32 
GeneralRe: Code generation error Pin
Syeda Anila Nusrat3-Jun-10 14:44
Syeda Anila Nusrat3-Jun-10 14:44 
GeneralRe: Code generation error Pin
ipadilla3-Jun-10 20:40
ipadilla3-Jun-10 20:40 
GeneralRe: Code generation error Pin
Syeda Anila Nusrat3-Jun-10 21:47
Syeda Anila Nusrat3-Jun-10 21:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.