SQLite Database in .NET MAUI App (Android,IOS,WinUI)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back once again in this video we look at sqlite database designer.net Maui application using the visual studio 2023 but before we get started please make sure you subscribe to the channel if you haven't so let's get into it then so as you can see I've got a visual studio Community 22 Visual Studio 22 Community version open let's get started by creating a new project so on the new project dialog yeah on that on the all projects yeah let's select Maui and then marry app yeah this is a project for creating a.net Mario application for iOS Android Mac Catalyst win UI and whatnot yeah so let's select this here and then here obviously they configure your project details but we're not going to look too much into that so let's click on the next one you can select your.net framework as well and let's click on the create project created for us here so let's do a little bit of clean up yeah so on the main page of Samuel let's click on it so here we're going to remove uh pretty much everything and and let's leave just one level okay so we're going to remove the image all the way to this level and we're going to remove the button as well so we're just going to leave this we're just going to leave this level here okay and then we open the code behind yeah so mainpage.zamo.cs so here we're going to remove the on the counterclick event okay I'm going to remove this as well so we just go and we're just going to remove this field so we're just going to be left with this only okay so what we're doing next is our you're going to add a class so let's add a new class so let's call this class uh sqlite DB contest okay so let's make this public and then let's open the new game so management you get packages let's browse so here we're going to add physical like net PC sqlite.net.cc so that will be the first result okay so let's download and install it so we've actually installed this package so let's go back to the sqlite DB contest here so on top here let's add these models so it's a public class let's call this product so uh let's add okay this field name for the product name and let's add this um okay price so let's make the data type double and let's add ID as well so on top of the ID this is what we're gonna put we're gonna put the you're going to make the ID that's probably and let's book Auto increment as well on top of it so you leave it as it is here okay so we only have ID name and price so let's come inside that top time in the the SQL light class yeah so let's add these fields yeah so this let's make this Con constant string and let's give it as a database file name and let's call this um we call like database Dot db3 okay and let's add this as well [Music] uh static screen and this will be our database path so this will be uh dot combine so this would be uh let's put file system file system dot updated directory and then the database file name okay so let's put this as well I have this constant uh sqlite Dot sqlite office so let's call this flag this will be I'm going to paste this here so you can have a look at it so I'm not going to type everything just to make it fast so this is where I've actually pasted so have a look at it and type it yourself okay this is just to make the video faster so we're going to also um sqlite mainstream connection and we're gonna name this database okay so that's all we have for here now so let's put this method here this will be an async method um facing task and we're going to call it in it okay so here we're just going to configure our database okay so we're gonna say is a database is not now this is what we're going to do uh let's say we're just going to return otherwise to put this variable foreign database Dot create table at create table async so this will be products table okay so we're just going to leave it here after this now and then what we do next is uh we're just going to put some method here to query the tables so the first method will be it's a public facing tasks list so I'll put a list of products okay and we type get our products so we first of all get that init method so we await the image method and we return the return um I waited database Dot table products that's the list Hastings okay so that's what we do for this necklace here so we'll go on to another one another method is public test product and this will be get product AC so this will actually take an inch uh product ID so I wish the energy and return I wait database Dot table products that's aware feeder product ID reader ID okay so we're just gonna put this yeah so this dot where T is equal to the product ID then we select the first the um the first or default async okay so that's what we've got for this method so the next one is of course add products method so let's go public facing add products okay if the a string task sorry task is so this will be add products a string so this will actually take a product so we await in it and then we check um if product dot ID it's not zero okay and we return now wait database dot update update async product okay health return a week database Dot can you set cases the product okay so that's what we're gonna do for here for now see we can add another method to delete products but we're not going to add it or you can do that yourself here this is just for gravity of this video okay so we go to the next part so we open the Maui Maui program.cs and scroll down just before the return Builder this is what we're gonna do uh Builder the services dot add Singleton at Singleton so this will be our SQL like DB contest yeah so this is what we're going to do here so we're coming back we come inside a main the main page the xml.cs so right after the the initialized components here's what we're going to do first of all you're going to start this field yeah so this this will be a SQL DB contest so we're just going to name this DB so right after the initialized components we're going to visualize the baby and then this is what we will do we're just gonna get the products so public variables this will be products and this will be TB Dot get our products that result Dot first or this Force okay so we come inside the main page dot Samuel and here obviously the label we're just going to add this to the label we're going to give you a name so it's X name we're just gonna call it uh product label okay so now what we do is we're just going to build that application now we have the project built let's go back to the name name page.sama.cs okay so here we've got the the product so let's add it to your product label let's add this to product label.test so this will be equal to so let's add a electron dot name product dot price so we're just going to display just a product name and the price okay so let's go ahead and run it and run it so it actually is running on Windows machine so let's select our and Android emulator so I'm just going to select one of the Android emulators but as you can see inside the DB contest here we've got no products no product added so this is what we're going to do we can't we get uh initiate a Constructor so here is that or maybe not even a Constructor but we're going to put it inside the image so I'm just gonna copy in Facebook so you just have a look and do the same thing okay so I'm gonna copy and paste this so have a look you can pause the video so this is what I've actually copied and pasted so have a look and type the same thing so we're just going to select the first product which is the the man goes in the price okay so let's run the application and see what actually comes out of it okay so I missed my ask me to take a while so I'm just going to pause the video right the whole thing runs okay so as you can see here now you've got a application running and we've got this um product showing okay so as you can see it's not really complicated but you have to make sure you go through all the steps you have to get to this point okay so I'll provide the source code for the members so if you're a member of the channel then you can request a source code otherwise please make sure you you follow the video very carefully so I'll leave it here and I'll continue on my next video so once again if you haven't subscribed to the Channel please make sure you do it because I've got lots of videos coming up and I hope you have a lovely morning afternoon evening Wherever You Are peace
Info
Channel: Hacked
Views: 3,861
Rating: undefined out of 5
Keywords: sql for beginners, sql tutorial, .net maui sqliite, sqlite, sqlite databae, sqlite database in visual studio 2022, visual studio 2022, sqlite visual studio, database, relational database, serverless database
Id: 1x-fFxoqyW4
Channel Id: undefined
Length: 22min 46sec (1366 seconds)
Published: Fri Aug 18 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.