ASP.NET CORE MVC Tutorial Step by Step 02 : Connect to Database ( PostgreSQL )

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
uh hi this is our net corrupt basic tutorial part two and today i'm going to talk about how to connect to the progress sql database also now let's go uh on how to set up this appropriate seo so let's download and install the project hcl this is a url so let's go into this uh download page so this is the program here logo with this error front and the header error frame and this download password is progress here so you just select your your machine os so i'm using windows so you just click on this window here so it will come to this place over here so you just click on this uh download the installer and it will bring you to this database download so you just select the latest version now it's a 13.3 so window is over here so now this version only available for the window with the 64 bit your window is still 32 bit so you you only can download the version 10.17 so that click on this download and just follow the procedure the instruction then you will have this uh program seo installed into your machine so let's open up this project sql so this is the outlook of the progression system so initially if i had assigned this upgrade crs server for you you want to create your own server you right click on the server and select create and then select the server and then you'll give the nand or server maybe i'll just call it a potato and then you need to go to the connection and you can uh because now if you are you had a server you just put in the server address maybe 10 point something like this or you are in yeah you also can use this localhost as an hostname then you need to provide a password and just click on this accept button and you will create this uh the potato server for you open up this server and you need to create a database on the database you right-click again and select create and then database here you just create your database you can get any name you write by nanoparticle and then just click on this access button and you are going to create this the server for you and you need to uh on this over here you have this uh the login group the role you need to create your own uh i mean you need to create owner for this uh for this database so you right click and select create and select this uh create row and get a name i just just call it the protector and then click on this save button and then you have this uh later on over here you can check on this property and you need to give it some preparation for example you can do loading it is the super user create you can create it also this one depends on your necessary so just save it go back to your database and click on this property and on this owner over here you can us select your all the owners that your creator just now is a potato so next press create click on this save button and next you need to uh create a table or this is a database so you go down to these screens and schemas here i'm not going into this detail about what is the schemas or all the turn over here because uh my main purpose of this tutorial is not to teach the program sql i will just show you the simple basic command how to procedure how to create a table in the data database so now you don't have a table you need to create a table so you directly again select tree in the table and you get a name for the table maybe maybe this will be your user table it's a thai user and the owner you select the potato and you need to create some current for this table so you click on this button and then you can create start to create a current you need to provide a nano the current and you need to know you've got to remember that order then inside here had to be lowercase you put uppercase there will be a problem in the future when you do the sql code so i just set this id as my primary key and the data type i jump let it be the bit integer so i need another column name and maybe decide this one called name and character variant and you need to provide the land that the user cannot uh over key the key in and then over the limit on this land so maybe i just put 10 and another one maybe a quick course or maybe i'll just create a email address send this one is also belong to the character and for the email may be slightly longer 20 and next and it's also belong to the character you can type the c over here to be review this greater variant designs output 10 you also cannot put the integer maybe something right around maybe something quantity or this one integer after prints all the your the data the table fields fields you can uh just click on this uh set button and you will create this uh user table for you and this the other column that you have assigned to the table and you can view the data by a right click on the table and select the view edit data and select all rows and you're going to these are all the the data inside this table and inside here you also can do some editing on the table or you can add some data inside here you can put one and then you can maybe put i don't know potato and email gmail and the department maybe era i don't know i t department and the quantity at any time we do after finish er editing this table you need to uh click on this uh button here uh save the data chain and now your data is set up successfully so this is how you create the table and the current or the table and the data into the design on how to create a database in the server in the program sql so after you create this uh table now we can start to uh go back to our visual studio to sign according to pull this data into our our view for the user to to view the data and this is the code that we had uh write in our last video and the first now the first thing that we need to do to let this visual studio can face the data from our program seo i mean and let this visual studio communicate to this separate sql we need to install a library called ngpsqr so to install this arrivally we need to install we need to install the library into our dependency the packet this is the package here so to install this uh packet the mp ngps qr library we need to go to these tool and go to the nugget package manager and select this uh manager nugget package for solution and we select that is the browse to find this package from the internet so we you type n gp sql and this uh this one is you just select it and select your project and create click on this install button and you're going to install this package for you you will just a click okay and this is the ryzen essex stunts you just click i agree i said you need to set this up right otherwise you won't let you install this package into your now already installed inside your dependency package and you can you will see that it's like mpg sql already installed for you over here so now you can cross this window so the next setting is you need to go to you need to go to this uh list you you go to loop for this file called the app setting dot json and you need to uh you you need to create a center connection change this one to or you can add another one by using the comma and say this is your you can render your server you can then use a contest connection your own you can then maybe use type my server so you need to type the uh you need you type server you need to provide the nano use server the location of the localhost is a your host name or your server this is your hotness hostname your server and then followed by the port and you still remember that just now we are in the proper scr when we create create this uh database we provide port as the 5432 and the database is a potato and the user id also protector and the pass well just now i said as a potato that's all the setting that you need to do on this uh fpp system you already uh configure this server information into this my server name here so you set the file and another setting that you need to do you need to go down to this uh style of trust file here and you need to go to the configure service you need to add another service is called a service add a single turn configuration another configuration actually this configuration is come from this one here so after you make this setting over here you can uh the next you need to uh i want you to create another file you directly right click on your project name and select this and then class i want to create another class called database enter and inside here you i want you to uh below here first let's create another class first call the server and public and ngpsql from the library connection connection and you have this error here you use your mouse cursor over it and then here the bug here you click click on it and select this one you'll see the library is this you see the npg sql library so after you input actually this one for you to input the library so that you can use the library object here so next time we create a server constructor so this will use the config icon f regulation server same thing before you use your mouse over here select this one and click on this one using the microsoft extension configuration so now you can attack a assigner a strainer object you can call it any name you write other conditional string string and the string format server dot get section and the first gate section is from the this start also is from this pp set setting is this you need to get this string and put it into here and uh the next uh get section will be your the string that are point to your your server is this one my server i'll just copy paste copy and then paste into here the top value so what i mean by this is a you are assigner this information into this object so after you have getting this information you can use this uh com equal to the new mpgs sql connection so we need to connect to the this public sql using this the server the information on the server so you just put in this uh this object name over here then after that you just type contour open it will start to uh fetch the data from the the server so we already are finished the setting for the server so next we need to make some settings for our database now let's do the setting on this database here first let's get this set this oj for the server and uh necessarily clear the private object to tie the screen and properly and next era just create this database constructor uh you don't know who is the constructor actually the contractor is the uh the first error the entry of this class it will be executed as long as the class have been called so it's a is the way that you write the class of programming language so now let uh assign this uh this uh sql into this our this uh the oj sql inside this class so you just type this sql equal to the sql data from there for the request and the server is quoted a new we call this a here that i call in the desktop server class so i put in this server the server equal to the this mean i already put put in a this information from the folder founder founder style here so that we can get this information and then put into here and you are going to assign it assigned to this uh mpg sql connection so next you type the np g sqr command all this is there are a command from the this mp gsql package or you can any query you can name anything right new pg sql command and er three are a parameter one is the the sql string here i will explain how sql screen later on in the server serverinformation.com sorry insert i had to put this it's this it's mean i call in a i calling this a com i put in this object into here so the last one is the data has to be equal to the query you need to this one is to let you execute the sql error to face the data in the database that's all that you need to already clear create this database class or call it library master library for the database so now we can start to uh invest our data the database data into our view from the controller so now go back to this controller home controller or maybe the okay home controller is if you still remember in our last video there i call this list data here so now i can take out all this i want to get the data from the database so i can start to write our sql command okay before before that we need to uh get the server reference from the this uh the apple settings so we could go to here and type this uh public icon configuration server i can't i we you need to are using this uh extension so that nets are in the in our home controller well we don't need this one this is a home control constructor we pass in this configuration eye configuration and you can any server and then we can utilize this server it's a this one equal to the server it's always for this one so now we can go down to our data is over here so we can write we can call our but before we call our database uh class we are we need let's assign the sql string the the command this is a sql command that will read the database data from the table we use the select followed by the current name we had a colon or name and the colon or email and the colonel uh department you still remember and from the and from the table name the domain is for the thought in iran so next uh we just call this our database class so assign a variable name now you can call anything you write i just call it db equal to new database and in our list database uh constructor constructor we had a one parameter and a two parameter so same right here so we need to assign a super number one is sql so this one is mui we assign our this uh this stream into this square here and the next one is this server so after that this miner these are so this this object will have all the property of this uh class over here you are going to have these sql properties several properties and the query and the data is query property so let's get back to this home controller so now you can put an if statement say if db dot and you can see after i type this dot it will restart all the property object like the data server is all from from here is this sql this data and the server so what you need here is the data dot has rows this one is also command from the ngps qr package this means if we have a data we can after we call this a command and we can get some data from the command then we cannot do the following so we can start to write the loop using the while root so while the db data read it may not even read the table until until end of the table until end of the data so next uh we can put this uh the list uh there is a data into here so now we can put the name we replay this data with the database data so db data zero we are counting the column by this one this one is a zero one and a two so you if you want this uh the data inside this the name current to be assigned to this and the name object here you have to put the zero here and you need to view the you convert it to stream so next uh the price within the price or maybe i yeah not you can add a object in this some model so we go back to this model the data model here so maybe we can add another one let's say the email and another one is a department so let's go back to the controller so now we can assign the email object with this uh data from the database one two string so next is the one so it's at the second data second current the b i think this will reset said we only need the setting to let the controller get the data from the database and pass it to the view to to display on the screen or the for the user so let's run this uh program i think there's something wrong with the table so let's go back to the our table our table name is the user it's not potato sorry so this one has to be user and then i run this and i i think i key in the wrong password so let's check the password again let's go back to this uh progress and under this uh log in group the role here the potato we directly and select this property i think i forgot to assign a password so i just report that and save to this system here and before i run this uh the call before i run this code i need to uh cross this uh database uh the server after we finish running this uh after we finish facing the data from database and assign the data into the wrist model so we are going to call this a inside here sorry i forgot to uh create another method called the cross method to cross the server so you need to say the server dot com dot cross like this because it is not a constructor it's the main method so you need to uh type void to say no return nothing if you want to return something you need to put strain integer something integer assignment and it is also our topic so go back to the controller so now you can have this a crosser object this is how you cross this connection with this progress serial so let's run again this chord again this time here poke out that the current nano gunner assist these are the users you can use this keyword the user because it has been a receptor by the sun somewhere else so we need to call it another name so go back here so let uh put a td for the table and go back here and we change this uh table name to dd underpad user intersect and open it and try to run again and this is to be okay now yeah print out this particular from the database first uh let's try to clear a table to to reach out all the the data so we go to the view so we go to the build the home index instead of using the list we can now use the table and uh we can use this uh here and by the td or you can create a title th say that this is the name department under email so you can uh go to the available uh loot css file here you can me go down here and you can say you wonder this is the table th or the let's try to run this one before i set out this uh css for this table now the data are very ugly in a very ugly way so you need to use the css to make some styling so let's go back again here and you can set uh you can put a browser so now our number let's go back to this uh table over here is some some data here number two is uh [Music] and go back to try to run this uh call again and now you have the three data but you don't need this start uh assign it into it because uh we are we need to refresh this uh css from because we just created uh in the description from spreader and let's go down to this uh they open up this uh the master pass here and you can see that this is our this is the section that are we are assigned our library and the css for the javascript prior and for this cs file we need to add another command color a append version to true so now i'll let the run again this miner it will auto refresh this css file by assigning the new version for this uh the css file you can see that it assigned a star into this table and there is now a loop better than before so this way however you will get the data from the database by using the progress sql so i think that's all for today so if you got any question you can just comment below and i will see you in the next video thank you
Info
Channel: potatoscript
Views: 1,212
Rating: undefined out of 5
Keywords:
Id: o2CBoIWOsyE
Channel Id: undefined
Length: 29min 21sec (1761 seconds)
Published: Sun Aug 15 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.