CRUD (Create, Read, Update, Delete) in asp.net MVC 5 using ADO.Net

Add connection to your database in web config
Run the following script in database. for creating table and stored procedures
Folder structure in the project

Add class Extensions to your project (DAL Folder)
Add class MyConnection to your project (DAL Folder)
Add an Interface IDbCommon to your project (DAL folder)
Add class TEmployee to your project (Models folder)
Add class EmployeeDAL to your project (DAL folder)
Add controller EmployeeController to your project
Add view to index action method
Add view to create action method
Add view to DeleteConfirm action method
Add view to Edit action method
In MVC a default approach for database operations in Entity framework. but we can also use an ADO.NET for CRUD operation in this article we will learn how to do CRUD with ADO.NET in MVC. Create a new web project using visual studio (created in 2015)

Add connection to your database in web config
1 | <connectionStrings> |
1 | CREATE TABLE [dbo].[Employee]( |

Add class Extensions to your project (DAL Folder)
1 | using System; |
Add class MyConnection to your project (DAL Folder)
1 | using System; |
Add an Interface IDbCommon to your project (DAL folder)
1 | using System; |
Add class TEmployee to your project (Models folder)
All the properties in a class should be checked with sql server table. (datatype and name should be same). the TEmployee structure in my case is the following.
1 | using System; |
Add class EmployeeDAL to your project (DAL folder)
1 | using System; |
Add controller EmployeeController to your project
1 | using System; |
Add view to index action method
Index view should be look like this
1 | @model IEnumerable<MVC_CRUD_ADO.Models.TEmployee> |
Add view to create action method
create view should be look like this
1 | @model MVC_CRUD_ADO.Models.TEmployee |
Add view to DeleteConfirm action method
DeleteConfirm view should be look like this
1 | @model MVC_CRUD_ADO.Models.TEmployee |
Edit view should be look like this
1 | @model MVC_CRUD_ADO.Models.TEmployee |
1 Comments
Awesome post. You Post is very informative. Thanks for Sharing.
ReplyDeleteASP.NET Training Institutes in Noida
Post a Comment