Simple Application with Insert Update and Delete

As you seen ,....... how to to connect database using entityframe work.
No my next session how to Insert Update and delete.

1. Create the table ,   for an example Emp Table

Sql Query:- Emp Table

CREATE TABLE [dbo].[Emp]
(
[Id] INT NOT NULL PRIMARY KEY IDENTITY,
    [Name] VARCHAR(50) NULL,
    [Salary] DECIMAL(18, 2) NULL
)



2> Create the Model --> Right Click add new Class  and Name EmpModel

Model :- This class is the bridge between Controller and the View

      [Table("Emp")]----> System.ComponentModel.DataAnnotations namespace included-->[Ctrl+.]



DbContext :- dbcontext is the primary object which interacting with database with using Model.
using System.Data.Entity; [Ctrl+.]
Add DbSet property to the dbcontext class.

  
Controller: this class perform as a get or post Action , according to client request.
Only Index Action --> just show the exist data in a table.

Index Action:- Display the List  in View.


View : It is GUI part which show the controll through which perform the action , Request or Post done.



After Running in the browser


Create : Insert the Data
.




Run the create page.


Update the data for that we need unique identification .. so we need id here


Goto Index page and Edit link is there in grid and hit the link to appear Edit page with unique Id

Delete -->Same as update you have to pass Unique identification so that row can be delete.


Share this

Previous
Next Post »