Login Form in Visual Studio .NET Core Windows Form Application with phpMyAdmin MYSQL Database

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this video we are going to see how we can connect to mySQL database in visual studio.net core Windows Form application and we are going to read data from the database that means we are going to create a logging form that means we are checking username and password.acos and matching available in the database so firstly I am going to create a database in phpmyadmin for that you can start your Apache MySQL and these kind of things you might using Sam fam or any other you can start my SQL server and then go to your local host then here I will create a new database the database name I will say logging create now there are no such tables so I will go ahead and create a new table the table name will be user users and then let's keep one column for user ID one column for the user name and one column for the user password and then I will create a better we could have four columns to store the user pass user name username means the you know first name and last name now here the first one is uh ID user underscore ID and this should be in uh in it and also I will say Auto increment then this field will be identity so this will be the primary key and so I will select the next column name as uh username name password so username will be Watcher and I will say something around normal usernames no more than 50 characters so I will say 50 and then name I will Define the name as let's say 100 characters and password also hundred now uh that is it so here the name should be voucher password should be vaja so we cannot allow the every Fields be null so I will keep this at is as it is so I will press save now okay now I'm going to add some sample data here so I will go to insert user ID as default and then username I will say admin name as a chain password as one two three four go okay the data has been added to the table now we are going to create our Windows Form application remember if you are using.net framework this will not work for you you had to use dotnet core you might uh find another video for dotnet framework this way is working only for the.net core so I will go ahead and create a new project here I will select the Windows Form app and then uh this should be here you can find the project here also but this is the recent project templates if you cannot see that here you can search Windows Form now how we can select the dot net core application the thing is that's not containing the dotnet framework text so you can just select this on Windows Form app and then it is in C sharp form and then uh I'm going to select that and press next here I will just keep the project name as it is and then next okay all right now the project is created the next thing I'm going to do just open nougat package manager go to tools and then select the nougat package manager go to manage nougat package for Solutions here you have to search my Square then scroll to the top otherwise you will not see the result I will select this and here check the project then click install remember this should be mysql.data okay now search nougat dot framework oh that should be no good thought framework here result will come go to the top otherwise you will not see the result check your check boxes and then click install it will be added into your project now how we can confirm whether these are installed or not go to this dependencies inside the packages you will see the MySQL data and then you get Frameworks okay now in this form one let's see yes I'm going to add my interface let's create some simple interface I will add a label so the text will be username I will duplicate this into deposit okay now let's go ahead and add text fields that we can enter values it is the text box now you cannot if you cannot see the toolbox you can just go to view and then select the toolbox here this is the toolbox you have to select okay that is fine now I'm going to duplicate this text field and then add that to the down now we are going to define the name for this text box in this properties if you cannot see these properties you can just right click this element and click the properties and then here we have to find the name in this design section you can see that name available I will change that into the text box username and the password I will change that name in the design section into text box password so we are going to add a button to login I will say login okay now I'm going to just double click on this button so it will create the click event for us then here in the top before the name space I'm going to say using MySQL dot data Dot MySQL client and then semicolon here I'm going to say my a square connection MySQL connection as the variable name is equals to new MySQL connection and then parentheses semicolon now we have to create the connection listing for that I will say string uh my SQL count is equals to double quotations and then semicolon here I'm going to write my connection string first one is the server what is the server I will say that is equals to now go to your PHP my admin then go to the home page now if you are using a cloud environment you will see your IP address here or here otherwise you might see the localhost now in this case I am seeing the this IP address so that's why I'm going to copy that and then paste that here and then next one we have to say what is the user I will set that day goes to now if you don't know your user go to your user accounts in the BHP my admin here to this IP address this is the username and there are no such password so we can go ahead and continue user as root semicolon and then the next one database is equals to the database name that we created which is logging and then password there are no such passes so I will say password is equals to just keep that empty like this there are no not no value so in this parentheses of MySQL connection I'm going to pass in my MySQL connection string all right that is it so after I'm going to create a if we statement to check whether you have entered the username and password and if there are nothing we have to show a message so here I'm going to create a string to store the username string username essay goes to text box username Dot text Dot to a string parenthesis semicolon and then next on string password is equals to text box password dot text dot to string and then parentheses semicolon okay now if we statement I will say the uh text let me just say E string Dot is not low empty and then parenthesis I will pass in username and then I am going to add o with this two pipe we can say o that means if one of these conditions are true that means there are no such values that case we are going to show a message the password and username is record string dot is not low empty I will pass in the password in this parenthesis also finally let's go ahead and show a message box Dot show I'm going to say no empty Fields allowed in the LC statement I am going to say SQL command MySQL command MySQL command as the variable name you can use whatever you want I will say new MySQL command now inside parenthesis first parameter we have to pass in what is the query is is this selector we are going to say select all from users I think that is the table name yeah uses uses and then the next one we have to define the connection string the connection string is this MySQL con okay uh that not should be let's see MySQL con yeah that should not be the connection string but it should be the connection is square connection I'm sorry this should be MySQL connection all right and then I'm going to write minus Square data reader reader is equals to MySQL command the command that we have created here and then I will say execute reader parentheses semicolon okay now I'm going to use a while loop to read values I will say read a DOT read okay now inside braces I am going to check if the username is equals to the reader Dot get this string the column name is username and deposit username and we are going to add the Andy statement password is equals to password dot equals parentheses inside parenthesis I will say read a DOT get this string and then parentheses inside parenthesis I will pass in my column name is deposit okay now if these conditions are true then we can show login is success message box dot show logging success now you can go ahead and play what you want I will add else a statement for this if we statement so I will say message box dot show invalid login okay now we are going to test our application username is admin password is one two three four okay now I will say admin password as one two three four okay uh there are some error ah because we haven't opened our SQL MySQL connection that is why this is happening so in the top before the MySQL command I will say my Square uh connection MySQL connection Dot open parenthesis close and after this while loop I'm going to add the MySQL connection dot Clause remember you had to use try catchy statement okay otherwise if some error occurs in the server side the application will be start that's why we are using try catch so I will say admin password is one two three four okay login success now let me go ahead and quickly show you how we can wrap these chords with the try catch here uh I will say try braces and I will cover the braces here catch enough the braces I will say catch and then parental is exception EX all right okay that is it for this video If this video helps please subscribe to my YouTube channel thank you
Info
Channel: Coffee Programmer
Views: 2,901
Rating: undefined out of 5
Keywords: visual studio, mysql, mysql database, mysql visual studio 2019, microsoft visual studio (software), mysql visual studio code, mysql for visual studio, mysql for visual studio 2019, database, visual studio 2010, mysql database visual studio 2019, how to connect to mysql database, mysql (software), adding data into database using visual studio mysql, create an interactive mysql database connections, how to connect mysql database to visual studio 2010, login, read, phpmyadmin, 2023
Id: wIlfXT5DzyI
Channel Id: undefined
Length: 19min 40sec (1180 seconds)
Published: Mon Dec 19 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.