CRUD operations using ASP.NET Core and ADO.NET

Project Download

Database Download

Introduction

In this article we are going to create a web application using ASP.Net Core MVC and ADO.NET. We will be creating a simple student record management system and performing CRUD operations on it.

Prerequisites

  • Install .NET Core 2.0.0 or above SDK from here
  • Download and install Visual Studio Code from here
  • SQL Server 2008 or above

Creating the Table and Stored Procedures

We will be using a DB table to store all the records of the student.First of all we will create a Database named StudentManagement”.

Then we will create a table named “Student”.

Now, we will create stored procedures to add, delete, update, and get student data.

To Insert a Student Record

To Update a Student Record

To Delete a Student Record

To View all Student Records

Our database part has been completed.

Create the ASP.Net MVC Web Application

Now we are going to create an ASP.Net MVC Web Application. The project Name is “StudentRecordManagementSystem”

Click Ok button, Then a below window will appear on screen

Click ok button, Solution creation has done with loading all needed files. Given below is the picture of solution structure.

What is MVC

  1. Model: Classes that represent the data of the solution and it enforces business.
  2. View: Simple word view means UI (User Interface) which dynamically generates HTML responses.
  3. Controller: A Controller is the link between User and System. It handles incoming browser requests and after process using model data or specific task, returns a response to the browser.

Create a folder named “Utility” in the project. Now we will create a class named “ConnectionString” within Utility folder.

After that we will create a class named “Student” within model folder

We will Rebuild our solution and create a “StudentController” within Controller folder. Right–>Add–>Controller –>Select MVC Controller with read/write actions and click add.

Another windows will appear on screen

Our StudentController has been created.

We have to work with database so we will create a data access layer class within model folder named “StudentDataAccessLayer”

Create Action

Now we will work with Create Action within Student Controller. There are two Create Action one is GET and another is POST. Now we will create a view for create action.

Before creating a view we will create a constructor

Right click on create (GET) action then click add view below window will appear on screen.

Click add

Now run our application

We will remove Id field from view. We have done auto increment of Id field in database.

Now we will work with Create (POST)

Index Action

We have to call GetAllStudent method from StudentDataAccessLayer class for getting all student in Index action

Right click on Index action then click add view below window will appear on screen.

Click add

Student save and show list has been done. Now we will save a student and see student in list.

Save a student

Show student list

Edit Action

Now we will work with Edit Action within Student Controller. There are two Edit Action one is GET and another is POST. Now we will create a view for create action.

We have to call GetStudentData method from StudentDataAccessLayer class for getting student by Id.

Right click on Edit (GET) action then click add view below window will appear on screen.

Click Add

Now we will work with Edit (POST)

Edit option has been done. Now we will test is it work or not work.

It is work fine. Now we will work with Delete action.

Delete action

Now we will work with Delete Action within Student Controller. There are two Delete Action one is GET and another is POST. Now we will create a view for delete action.

We have to call GetStudentData method from StudentDataAccessLayer class for getting student by Id.

Right click on Delete (GET) action then click add view below window will appear on screen.

Click Add

Now we will work with Delete (POST)

Details Action

We have to call GetStudentData method from StudentDataAccessLayer class for getting student by Id in Index action

Right click on Details action then click add view below window will appear on screen.

Click add

Output:

Hope this will be helpful.

Leave a Reply

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