What is CRUD?
CRUD is stands for "Create, Read,
Update, and Delete".
These are the four basic
operation for managing data in an application.
In
HTTP we find four main methods that can perform processing on
data that are defined in the REST architecture. This correspondence can also
be done with CRUD.
GET
-> Retrieve
POST -> Create
PUT -> Update
Delete
-> Delete
CRUD Operation
To Insert
Public class HomeController: Controller [HTTPPOST] //controller is a class public ActionResult InsertData(Students s) { ApplicationDb db = new ApplicationDb(); db.Students.Add(s); db.SaveChanges(); return view(); }
To read
ApplicationDb db = new ApplicationDb(); var lst = db.Students.ToList(); List<Students> list = db.students.ToList(); foreach(var obj in list) { console.writeline (obj.StudentsId); console.writeline (obj.StudentsName); }
To Update
ApplicationDb db = new ApplicationDb(); Students s = db.Students.Where(x => x.StudentsId == items.StudentsId).SingleOrDefault(); //items is a model name s.StudentsName = new StudentsName; db.SaveChanges();
To Edit Single Update
Public Class HomeController: Controller { ApplicationDb db = new ApplicationDb(); Students s = db.Students.Where(x => x.StudentsId == StudentsId).SingleOrDefault(); return view(s); }
To Delete
List <Students> s = db.studentsToList() if(s!=null) { foreach(var t in s) { db.students.remove(t); } db.savechanges(); }
Disclaimer
All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.
0 comments:
Post a Comment
For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.