Performing CRUD Operation In .NET MAUI (SQLite)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Music] hello guys welcome to my channel in this video i am going to show you demo regarding crud operation using sqlite in dot net mavi application here i just created a new project so let's install required plugin in this project so this much plugin are required so let me install this all plugin in our project so just right click in your project and click on manage nuget packages and install this all packages one by one so okay let's see now in install so all packages are installed like if you not install this all packages then you will get some dll import error so for that reason i installed this all packages now let's create a structure for it so i'm just going to display some student list so for that let me add view and view model for it okay so let's add now student model okay so this much property i am just going to use and here i will set student id as a primary key and go to increment okay so student model is designed now let me add views to display student list so here i am just going to add content page for [Music] student list page okay now let me add view model to it okay now i'm just going to register this view and view model in my program.cs so here i will register for view then view models and the services that i am just going to create now let's inject this to that list view model in student list page so here i will just ask q model and set this page contacts to this view model okay now let's set this page as a startup page so in app cell i'm just going to set the name space here to views [Applause] and here views dot student disk page okay so now let's run the application and see like this page is displaying or not okay so now it's displaying default page as a student list page let's create a services now so we can access like some that student list then inserting student updating student that all details so for that i'm just going to create folder [Applause] called services and here i'm just going to add interface and another i will add class [Applause] student service that going to implement interface okay now let's add here one method that going to written student list this i'm just going to implement in student service let's create another method [Music] student model object whatever the object that we want to delay that will i pass and another one is update student here also i will pass student model with updated details so it's going to update now let's implement this all method here okay now i'm just going to do database setup here so when the constructor call that time i am just going to create here a property sqlite passing connection here i will check like if the database connection is null then just set up for it so here i will add db part wooden dot dp3 create table let me create here one method and this all stuff i'm just going to add here okay so now i can use this db connection for inserting then deleting records and for getting records so let's first get the record so here i just need to use table and whatever the table name that here i just i'm using this class is a table name also you can do one thing here you can provide annotation like this table and here you can specify the table name if you want some custom table name right now i'm using this student model as a table name and just choose to list the thing so it's just going to return student list and just return it okay now for writing i'm just going to write something like this here insert a scene and the object so for add student i need to pass objects that i forgot to add so let's add here and this student object it's going to return okay so also it's going to return integer value means if the record is added then it's going to return integer value so let's change this in interface for add student i'm just going to use integer and student model that we're going to insert so same way delete student here i will pass student model detail and this also going to written data in integer format like it will return the record number of rows deleted so if it is one then we will identify as a record is deleted same thing here in update also we write same logic update async and it's also going to return integer value number of rows updated so let me set this up and also let me set this detail here [Applause] okay so structure for like a service structure is ready for write student delete student and get student list so let's now create ui for adding record and adding updating and deleting the record so let me okay so let me close all pages now here i am just going to add another page called add update student [Applause] and same detail here i will create view model for the same now let me register this view model and views here [Applause] also let me register service that i created okay now let me inject this add or update student detail view modeling student details so here i am just going to use property that i declare first name last name and email so let me write so i will navigate to this page on the click of add student or update student so let me add here one button for adding student at student and in view model i will add command to navigate to add student list of the student list so for that i am just going to use another plugin mvvm community toolkit so let me install that [Applause] so this one microsoft toolkit. so i will navigate now to add student so here i will just specify that okay so this adder update student detail i need to register this space in a routing also for that in app cell the gmail.cs here i'm just going to register and the root name i will use same as a page name and it will be the type of page okay so now on the click of add update student command it's going to navigate to add update student detail so let me bind this command here okay now let's run the app and see it's navigating to add average student or not okay now on the click of add student it navigating to address student detail page now let me add here button to save the details of students okay i'm just going to now add style here so let me remove now style font size from here as i have added common style for label also okay now let me grab this all in vertical stick layer okay now on the click of save button i am just going to add this record in student student model table so let me now add command here [Applause] okay so here i'm just going to use now observable property for first name and last name and email so let me bind this in ui and the command name will be this add student command okay now here i need to accept service so let me create my student service object i already registered this student service in uh mavi program dot cs so it will be accessible now in the view model so i just need to pass here now student service dot add student and model name here email will be this email then will be whatever the observable property we declare from that same last name also and student id will be auto generated so here i will check if response greater than 0 that means that code is added so right now i will just display color type like a record i did okay now let me run the app and see like record are inserting in student table or not okay now let me try to add record okay so it's showing me as a record direct to student table now let's implement like let's display this student list here on student list page so for that let me add observable collection property on student list page view model so here i'm just going to create observable collection of student model also let me add here student service that let me copy from here so we already registered the student service in mavi program.cl so it is accessible so i just need to access it here i will check like if the student is greater than 0 then i am just going to add that in students table and before adding i'm just going to clear it so whenever we call it's going to just clear this student observable object and after that it's going to add recording students table this students object now like i want to call this matter get student list whenever the page appear so for that i'm just going to here overwrite one property on up here and let me access view model here so this view model i'm just going to assign here and i will call this cat student please matter so let's create command so i'm just going to invoke this command from here [Applause] so right okay now let's bind the student list to ui so this students of chair i'm just going to bind it here in collection so let me create collection view okay now let me run the app and that's it's displaying student in collection view or not okay so here it displaying one record let me add another so it is playing okay so now it's displaying here and let me just do formation here okay now i'm just going to implement now edit and delete feature like on the click of this collection view item i will display one action button and in that i will display edit and delete option so let's implement that so i'm just going to create now command and here one button will be a added and another for delete record so when the response like is equal to delay then i'm just going to call student service dot delete student and in this i'm just going to pass student model so for that let me patch student model here and this i am just going to pass here and if delete response greater than zero then i am just going to call this get student please come on all the things of this student list matter okay and on edit i'm just going to pass i'm just going to call this add update student detail page with a parameter so let me add i need to add here navigation parameter so that will be in the dictionary format string and object so let me create and here i am just going to add [Applause] okay now on app update student detail view model i'm just going to access query here this navigation parameter using query property so before that let me create here observable property of student detail name and here the key will be whatever the key here i have specified that key i need to pass here and first will be the name of uh property whatever the property you declare here so i'm just setting uh name as a student detail here now let's find this student detail in ui so for that before i am using like a first name last name now i will use like student detail that first name student detail dot last name like that okay now i'm just going to remove these three properties because we are now accessing this from student detail model so here now student details now let me run the app okay before the running app i need to add also here on tap event like when i click on this frame so okay now part will be the command name so on the student list i am using this display accent command so that i am just going to set and command parameter will be current object now let me run the app and let's see like it's displaying student detail on add update student detail page or not okay so now it's displaying action button edit and delay so on the click of delay it's a deleting record and on the click of edit it's navigating to add update student detail page and here it binding that all the name now on the click of add student i just want to show you something here it's going to crash because the student detail object will be empty here in at student detail we are passing from query parameter but when we click on add button here then we are not passing any information so on the click of save button it is going to throw error as a student detail here if you see that student detail is null okay so now let's fix this so first i'm just going to add condition for updating student detail so if student details student id greater than 0 that means we are going to update record otherwise just we are going to insert record so [Applause] here i'm just going to pass student detail model for updating and if the response is greater than 0 then i'm just [Applause] going to stay here okay now here i will set default to new student order means like if we click on add button that time empty student model object will created of student detail so after that i can access this student detail dot email first name and last name another property okay now let's run the app and let's say it's working or not okay so let me try to address okay now it's in student input save recursive and here it is displaying and now let me edit that record and it's updating also okay so that's all for today i hope you like this video and thank you so much for watching
Info
Channel: Programming With Pragnesh
Views: 23,956
Rating: undefined out of 5
Keywords: CRUD OPERAtion, CRUD Operation In .NET MAUI, .NET MAUI, Performing Crud Operation In .NET MAUI, CRUD .NET MAUI, .NET MAUI CRUD, CRUD, .NET MAUI SQLIte, CRUD Operation With SQLIte, SQLIte Demo in .NET MAUI, .NET SQLIte
Id: JRNwjsywrWM
Channel Id: undefined
Length: 46min 23sec (2783 seconds)
Published: Wed Jun 15 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.