How to Create a Login Form in C#.NET using SQL Server Database and Visual Studio 2022? [Source Code]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys this is meon today we are going to create a login form using SQL Server database in Visual Studio 2022 so let's start first of all open Visual Studio and then click on create new project and from the template select Windows Form application and Windows Form application and then click next and then give the project name and then click next do and then click create it will take some time to render your Visual Studio because this is a bulky ID now after rendering uh go to the toolbox that is at the left corner if you don't see that option from The View option uh you can show your toolbox and from the toolbox you can drag and drop your control over your form first of all let me change the color of this form and the name of this form here from the text property and I can change the color from the back color property from here click drop down and you can choose from costom color web color or system color whatever you like here I'm going to choose from o color and okay I'm going to choose this purple color now from the toolbox drag and drop some controls uh we need two buttons here so drag and drop to buttons and we need a text box so you scroll down [Music] and back and drop to text box and then to labels also labels and then one check box checkbox and one link label and one picture box also now uh let's arrange this in a nice way and change the property of his controls now we have to change the variable name of this text box so here I'm going to write txt user and this this one is dxt pass and checkbox text change the text of this checkbox from the property this is so password this is a bit small you can increase the font size from the font property like Tu tuil is seems perfect now change the label text to username you can also change the color of this control from for color we're going to use the white color one and say the font size also this button is cancel button and this button is login button you can also change the size of this button so that it looks nice and change the color also you can also change the butter background color from back color here I'm going to choose the green one green and this is red and you can change the text [Music] color transparent sorry I change the back color not the font color so font color here and you can change the font size also and same process for this here go to and the color is transfering now this is the link level we are going to change the text of this link label also this size also font size and color also this color is it looks that good there you go now from the property of password text box and find the password character and here give you give the S sign so that when you type your password you don't see your plain text now select your uh picture box and choose your picture local import I'm going to choose from documents okay and you can CH the property from here there you go when you click that show button after running your application the password must be shown there if you check that check button now we finish our designing part save it now open SQL Server management studio if you don't have you can download it from Microsoft website and install it uh click connect after connecting right click over database and new database login app click okay expand your database that is login if and expand that also right click over table new table and here usern name data D is bcare password bar cash simply control+ s and give the table name login app okay now expand the table also right click over your recently created table and then click on it top 200 rows so that we can save some data here like admin admin you should not uh use this simple username and password in your real application I'm just using this for for the demo purpose uh click that close button uh the username and password will automatically save now go back to visual studio and go to server Explorer right click over data connection add connection refresh your server name your server name and click that server certificate and to your database my database is login a click okay now your visual hisory is connected with your SQL Server now double click that login button we're going to write the code and scroll at the top of your code and we need to use some directory here using system do data do SQL client and here if uh your intelligent uh does not so SQL connection that what you need to do is right click over your solution Explorer click on manage number package and browse and from here SQL microsoft. microsoft. data. SQL client you need to install that and click on install after installing this popup window will uh display click apply I accept and go back to your uh CS file and here inside clicking evit of that button SQL connection con is equal to new SQL connection and inside here you need to pass your connection string so select your database from the SQL server and go to property and copy that connection string contrl c contrl v and uh remove that uh space in the trust server certificate to true and here goes semicolon uh string query we are going to write a query the query must be inside the qu so here what we are going to do is write SQL quy select count as means count all the row that is affected by our uh where closes Parts select count from our table name login a where user username is equal to at the rate usern name we are going to use a parameter substitution here and password is equal to password semicolon now SQL command CMD is equal to new SQL command and here goes our query is a first parameter and connection is a second parameter and here we are going to pass the parameters so CMD dop parameters dot a with value and here goes adate username and this is replaced by txt user dot text CMD dop parameters. with [Music] value add password and this is replaced by txt pass. text now we need to execute our query before executing our query uh what we need to do is we need to open our connection so after creating the connection what you need to do is here connection do open and here int count is equal to we're going to save the uh executing query in variable uh because we need to convert that uh executing query into integer type so here we are uh using uh integer paring here command dot execute scalar and here we need to close our connection connection. close and if count is greater than zero if there is some rule that is affected by our quy then what we are going to do is message boox dot so login s success and info and message box button. okay comma message box icon do information otherwise what we are going to do is else message box do [Music] so eror in login save it go back to your design double click that cancel button when the user click that cancel button what we need to do is we need to close that form so this. close now when the user click this uh check box what we need to do is we need need to display the password so for that double click that checkbox and what we are going to write is txt pass DOT password character is equal to checkbox one dot checked and we are going to use the tary operator here question marks if the checkbox is not selected we are going to uh display the a if checkbox is checks we are going to display the pl text here save it go back to form now run your application now let's check if cancel button is working or not click cancel cancel button is working uh execute again here I'm going to use the correct username and password admin admin and click that checkbox so this is showing our password this is adding our password click login now let's check our query here stop eight uh query select count as from forget here from our table name where username is equal to this one and password is that one save it run your application again and uh interor username and password that is correct one that is save in your database so password click Loess information click okay if you enter the username and password that is not save in your database uh it must display error message error in login and cancel close your application and I'm going to show the forgot password system in the next tutorials and for that stay tuned and keep subscribing this channel for this next tutorial so that's it in this video tutorial guys if you like this video share this video with your friend so that they can know about this tutorials have a good day bye-bye
Info
Channel: RunCodes
Views: 6,113
Rating: undefined out of 5
Keywords: c# code for login form in visual studio 2022, how to create a login form in visual studio 2022, how to create a login form in visual studio, how to create a login form in visual studio using sql server database, how to create a login form in visual studio using database, create a login form in visual studio, create a login window in visual studio 2022, make login form in visual studio 2022, login form code in visual studio, login window code in visual studio, login form visual studio
Id: JgdPrbgHVoE
Channel Id: undefined
Length: 19min 45sec (1185 seconds)
Published: Thu Dec 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.