How to Create Multi User Login Form in C#.NET using SQL Server Database? [With Source Code]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys this is Madonna and welcome to the new video tutorial in this video tutorial I'm going to show you how to create a multi user login form in C sub dotnet using SQL Server database and creaturely studio that means when the individual login is a different role different form need to be opened means a redirect based on the user tool for example if the user login is the admin a different form need to be opened and when the user login is a normal user different form need to be upon so in the process of solving real-world problem you may need to develop sauce the system which may need to have a multiple user that is multi-user logging system in your developing application and when each individual enter their associated username password and their role they must need to relate to the only certain feature that they only need to use so in C sub dotnet this can be done by using combo box so let's do it first upon you need to have a basically studio if you don't have you can download it and install from Visual Studio calm and then go to file click on new click on project select the windows going to form application and give the name of your project log in form combo box click OK and then expand these palm drag and draw off three levels for username/password in for slick ting the user to give the instruction to the user and then drag and drop to tapes box in order to receive the user input and then on combo box to select the different user and then finally one button click this level and change the takes up this label to user name you can also increase the font size of this level from here put the font and then drag the false as you want and similar forces for this level to pass or and finally her goods select user type and this is the name of this text box so that you can remember this lamp while you were programming TX teaser goes txt pass and says the bottom button Texas will it goes login and slick this combo box and then go to the property of these combo box and find this item property and then click on collection so that you can hear the item I'm going to use admin and then normal user or simply user normal user these are two item click ok so we just finished the designing part of our application and you also need to have a Microsoft SQL Server management studio if you don't have you can download it from Microsoft site outside and then open this Microsoft SQL Server management studio go to right click this / database click on you did and give the name of your database and then click OK expand this database and just replace it and again expand this this will liquidate database go over table and right click over that table click on table and give the column damage username and data types should be back here and then so bad care and then user type bad cat in this control paste ctrl + S to save this table give the name of the drivers okay I'm going to cave login just expand this table and then right click over this recently create a table click on edit top two on the truths and here you can keep the value I'm going to give these enemies admin password is admin and easier type is it mean and again I'm going to give another username admin password is admin and then use your type to user and just close these windows it will save automatically these username password end user type so go back to visual studio click over this server Explorer and then here you can see this is your server right click this over data connection click on air connection this is the data source to SQL server click OK and the give the name of the server name my server name is rounded PC or you can select your server name by clicking this drop-down button and select the database that you recently created CMB log in and then click OK now our replication connected to our database select this data connection and then from this property copied the connection stream control C and then double click over this log in button and we need to import the namespace so we are going to write this using system door data dot SQL client so that we can write the scale so that we can connect our or this affection to our database so go back to the designing part of this form double click the login and then write the code over here first of all we are going to connect our application to the database so SQL connection con is equal to new SQL collection and inside these double quotes just paste the connection here a connection distinct that you recently copied now we are going to write the SQL command CMD is equal to new SQL command here we are going to write the SQL query select all from our table name is login well username is equal to sink two single quotes inside two single quotes to double cores inside to double quotes 2 plus sign and inside two plus sign we are going to access our textbox txt user dot txt in order to take the user input and pass so is equal to similar txt past North Tex and then we need to connect to our connection and we are going to use the SQL data adapter with it like an adapter between our data in SQL Server SQL data upload SDA is equal to new SQL data return and we are going to pass the command is a parameter and then we are going to use the data table DT is equal to new data table because in our database there is a table that we create and we are going to fill this DT dot sorry st we are going to fill this date adapter SDA dot fail by this data table and as is the thing when this application is drawn let me run this application here you can see user enter their username password and select their user type and then click on login so what we are going to do is when the enter their username password in select your user role we need to access only the admin or normal either to the next forum so what we are going to do is first of all we are going to read this coil right this line of poor if DT dot rules the odd count is greater than zero it means if that is something written by this query we need we are going to do something of press on else if the usual are give input is not mass and we are going to display the message else message box dots so either so when the user input username and password is maths we are going to do some operation inside this if statement so and again in the database that may be our number of first of all let me show you in this the table that may be a number of user type and there is a c2 username and password so what we are going to do is we are going to write the for loop which returns the who is read each line of row of our table this one is first row second row n there may be one n number of rows so for int I is equal to 0 I is less than DT dot rules load count it counts the number of row of our database table and then I plus plus we need to implement these and inside this if what we are going to do is if the user enter the right username and password then we are interred in this Farlow and after in this follow this follow what this for loop do is tell me where number of row in our tier or database table and this for loop take each number of row of our table and again what we are going to do is if DT dot rows that may be a number of rules so I'm going to pass this variable he is index and then either you can use two or this is the index 0 this is index one and this is index two or you can use the column name user type user type dot to string everything need to be converted in E string in C sub is equal to is equal to these are selected I am going to show you when like this item this item needs to be stored in some variable and then we are going to compare the database store this user type and then user selected this user type user selected this user type so for this we need to eat to this value in some variable so for this I am going to what I am going to do is string CMB item value is equal to combo box 1 dot selected item dot string and here we're going to pass this variable CMB item so window user selected combo box item is equal to these database already store or database either time then we are going to display the message then we are going to display the message message box dot so you are log in age tt dot root I danced to and again with these username and password mess in the user selected either type is meds we are going to open next form so for eating the form right click over all these solution project and then click on add Gilligan new item and then select the window form and then click L and again repeat these process click view in the form and then click it so what we are going to do is Eve in combobox we can exist the combo box in the EXO combo box wandered selected index selected index is equal to is equal to zero means first of all let me do never start this project this is the index 0 and then this is the index 1 so when the user click oh when the user click this admin we are going to display the different message like this form 2 F is equal to new palm toe we're going to we are going to create this object of this form 2 and then F dot so and then this don't hide means are this login under else else form three F F is equal to new form 3 FF dal-su and then these dot hide I have only two username I have only to users so I'm going to highlight this code it if and as if you have a multiple number of user then you can read if and hell else Eve combo box 1 dot selected index is equal to 1 and then else if combo box 1.0 to index is equal to 2 and it lasts you can use LC statement so I am going to explain about this code what we are doing is first of all we connect our application to the database and then we write the SQL query and then we use the data adapter so that out of our data is this data adapter it is the adapter between our SQL Server in our data and then we use the data table because we have the table in our database and then we fill this in detail returned by our table and then we store the combo box selected item in one variable and if digital root that count is greater than 0 means if the user input username and password is a mess then we are going to do this operation otherwise if the username and password that the user per barrel is not mass then this message will display and then as you can see here than air may be number of row in our database table so for this we are going to use the for loop so that this for loop written the number of the row and then if there are the number of the row then we are going to compare the user selected username I mean selected user type user type and the and this user type that we stood in our database and this is math if these two bellows is maths then we are going to display the best in your login it's either admin or either normal either end again if the user select the combo box value that is in index 0 then we are going to display this form and then else we are going to display the another form so just save it and then run it so if you enter the wrong password and then admin the message to display either but we got some little over here in valued of the will give the wrong table lamp so let me run again if you enter the wrong username password and then slip the end user message to display error and if you enter the correct username and password your login eads edwin and then this form will be displayed and again it bent and then admin and then if you slick these normalizer and then click login we get somewhere over here let me fix it oops I only give this user and then here I gave the item item it normally does so this is a little mess and wrong and nothing is it on my our program so let me run on it so a bit mean and then admin and then if you select this user and then click login message to display your login it's a user and then we need to redirect to the next form that is form three and again if you type wrong username and password in silicon user message to display error and if user type admitted win and then select the admin I says you display your login as admin and then form to need to be display so that's it in this video tutorial guides if you think this video helped you in some extent save this video with your friends so that they can know about this and give thumbs up which really motivates us to make a source of programming and take video and thank you once again for watching this video have a good day bye bye
Info
Channel: RunCodes
Views: 79,149
Rating: undefined out of 5
Keywords: C# multi-user winforms application, How to multi user login c#, Multi account login C#, Multiple Users from SQL Database for Login Form in C#.NET, Multiple users login form for starting application in C#.NET, single login form for multiple user in c#, Single Login page for multiple user in c#, Visual C# multi user windows form, multi user login form in c#, multiuser login form in c#.net, techsupportnep videos, tech channel from nepal, tech channel of nepal, ran, ranbk, techsupportnep
Id: QrsZ4DPCgpg
Channel Id: undefined
Length: 23min 30sec (1410 seconds)
Published: Sun Apr 22 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.