Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WinForms

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

4.88/5 (30 votes)
4 Jun 2010CPOL2 min read 180.4K   10.3K  
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)