CRUD – ASP.Net MVC, Web Api-2, Windows Form

In this article we will learn basic CRUD operation using Web Api-2, and Stored Procedure with a sample Desktop Application.

Download Source Code


Sample Database:

Let’s Create a Sample database named ‘SampleDB’ with SQL Management Studio. Using the ‘SampleDB’ now create a Table name ‘tblCustomer’.


Stored Procedure:

Now the step we will go through to perform CRUD operations with stored procedure:

  1. First we will create a stored procedure (SP) to RETRIVE record from Customer table
  2. Now we will create a stored procedure( SP) to INSERT record into Customer table
  3. Now we will create another procedure (SP) to UPDATE existing data in our Customer table.
  4. The last step we will create a stored procedure to DELETE existing record from customer table.


Stored Procedure to RETRIVE Record:

Stored Procedure to INSERT Record:

Stored Procedure to UPDATE Record:

Stored Procedure to DELETE Record:

Stored Procedure to VIEW Single Record Details:


Let’s Start:

Open Visual Studio 2015, Click File> New > Project. In this window give a name the project and solution.


Click ok and another window will appear with project template, choose Web API:


Click ok and the visual studio will create and load a new ASP.NET application template.


In this app we are going to apply CRUD operation on a single table named Customer. To do first we need to create apiController for the operations. To add a new Controller file we need to click right mouse an option menu will appear Click Add > Controller.


Let’s name it CustomerController. In the controller we will create action methods to perform CRUD operations:


Api Controller for CRUD operations:


Data Service:

As we know earlier that we will use ADO.NET, Stored Procedure so to connect data base we need to modify our config file to add Connection String for database connection:

Now we need to create another class to use connection string and open our database connection, let’s name it dbConnector.

To perform CRUD operations we will create a separate class called CrudDataService. In this class we have five methods that will interact with database to perform CRUD operations.

// Database Service

Publish the Site in IIS:


Let’s assign a port to access, In this case the site base url is: http://localhost:8081/


Let’s Create Windows Form Application:

Open Visual Studio 2015, Click File> New > Project. In this window give a name the project and solution. This time we will create a Windows Form Application.


In our new application let’s create a new Form, name it CRUDForm.cs2Our new form will look like this screen:


In CRUD form we have a data grid which will load all data from database through api controller.

Form Submission Code:

Desktop Application:


In this stage we need to input the HTTP Url to perform CRUD Operation through api controller.

Web Application:



Finally displaying data in both Web & Desktop Application at the same time using Web API.

Hope this will help someone  …Thanks.

2 Replies to “CRUD – ASP.Net MVC, Web Api-2, Windows Form”

Leave a Reply

Your email address will not be published. Required fields are marked *