TechSupportNepTechSupportNep - Programming & Tech

  • Home
  • C#.NET
  • PHP
  • JAVA
  • Python
  • ASP.NET
  • VB.NET
  • Android
  • C
  • Tech
    • Tech News
  • Patreoner
TechSupportNep
  • Home
  • Programming
  • VB.NET
  • How to Create Multi User Login Form in VB.NET using SQL Server Database?
VB.NET

How to Create Multi User Login Form in VB.NET using SQL Server Database?

By Er. Ran Bahadur B.K. Last updated Aug 15, 2021
1 4,297
Share

Hello guyz, if you are looking for the tutorial that shows how to create a multiple user login form in vb.net using SQL Server database and redirect to different form based on user role, then you are in the right tutorial.

First of all let’s understand what is multiuser login means; see a company may have a number of employees and each may have to access the same system from different computer that are connected through networking. And each employee have different designation. So, they need to access only their part in the system and should not access other’s account in that system. So the concept of multiuser in the system had evolved.

In the process of solving real world problem, you may need to develop such a system which may have multiple number of user of a single system and when each user login to the system they must need to access only the certain features of an application which means they don’t need to access all the feature. In general the administrator have access to all the features and normal user may not have. So, this tutorial is all about this.

First of all you need to have Visual Studio and SQL Server Studio. you all can download these software from microsoft official website.

SQL Server: From Here

Visual Studio: From Here

Steps:

1. Open your Visual Studio and click on File>new project, From the left side of your window, select Visual Basic>Windows and from the middle side select Windows Forms Application and then give the name of your project and then click OK which is shown in below.

2. Drag and drop three Label (for username, password and user type), two TextBox (for letting user to input username and password), one ComboBox (letting user to select the types of user like admin, user etc) and one Button(For login) from the toolbox and change the text and name of these control from the properties of these controls. And from the item properties of ComboBox add the items like admin, user etc. This complete the designing part.

3. To create a database and table in SQL Server Database, open SQL Server application, and Right click over Database and then click new, give the database name whatever you want and click OK. After then expand that Database directory which you can see in the left pane of the SQL Server Studio Software and expand that Database directory and then expand your recently created Database. And then you will see Table directory. Right click that Table Directory click on Table and click OK. You will see the new window which looks like this:

and then give the column name such as username, password, usertype, set the data type as varchar for each column and save that table by pressing ctrl+s and give the table name whatever you want.

And then Right click your Table and then select Edit top 200 Rows click OK and then write the username, password and user type(like admin, user) and click close button; this will save the username password and user type in your table.

4. We need to connect our application to the database for this, click on the Server Explore which is in the right side(may be left side) of the Toolbox in the left pane of your visual studio. And then right click on the Data Connection>Add connection. New window will appear select your Data Source; in our Case Data Source is Microsoft SQL Server. To do this click on change and select Microsoft SQL Server, Click OK. And then New window will appear, select your Server Name your Database Name and click OK.

5. Now Double Click in that Login Button (or right click over your form select view code) and write the following code:

a. import the namespace at the top of your code.

Imports System.Data.SqlClient

b. Inside the clicking event of that login button write the following code:


Dim con As SqlConnection = New SqlConnection("Data Source=RAN-PC;Initial Catalog=vbmultiuser;Integrated Security=True")
Dim cmd As SqlCommand = New SqlCommand("select * from login where username='" & txtUser.Text & "' and password='" & txtPass.Text & "' and usertype='" & cmbUserType.SelectedItem & "'", con)
Dim sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
sda.Fill(dt)
If (dt.Rows.Count>0) Then

MessageBox.Show(("you are login as " + dt.Rows(0)(2)))

If (ComboBox1.SelectedIndex = 0) Then
Dim a As New Admin
a.Show()
Me.Hide()
Else
Dim u As New User
Me.Hide()
u.Show()
End If

Else

MessageBox.Show("error")

End If

NOTE: Change this code in your context (because your connection string (Data Source = RAN-PC; Initial Catalog = vbmultiuser; Integrated Security = True) is different than mine)

6. Run your project by click the green triangular button, input username and password, select any comboxBox item and click Login. If your provided input is match with the database value you will be able to go to the new form otherwise get message box saying incorrect. That’s it.

if you like this tutorial don’t forget to share this with your friends and write your perception about this article in your comment section. Thank you 🙂

If you have any confusion, you can watch the following videos:

Continue Reading
code for login form in vb.net with databaseHow to make login form with different user level in vb.netHow to make login page code with multiple users simpler in vb?Multi user access login in vbMulti user in vb.netmulti user login in vbmulti user login in vb using sql server databasemulti user login with database in vbMulti user sql database vbMulti User Vb ApplicationMultiple user login using single form in vbvb form with multi-user login to sql serverVb Multi User LoginVB multi user login systemVB MULTIPLE LOGIN
1 4,297
Share FacebookTwitterReddItWhatsAppPinterestEmail
Er. Ran Bahadur B.K.60 posts 56 comments

Ran Bahadur B.K. is the owner of TechSupportNep who is working with the aim of providing the quality Technology content. He is creating Tech and Programming videos, you can see all them in his YouTube Channel(https://www.youtube.com/TechSupportNep). He is also working with some company.

Prev Post

How to Send Free SMS From VB.NET using SMS API?

Next Post

How to Generate and Send OTP SMS For Free using PHP?

Show Comments (1)
Help Needed

This website is free of annoying ads. We want to keep it like this. You can help with your support:

Donate!

The need for Support! Why to Support?

If you need your own website? contact me!
erranbahadurbk
Fiverr
Seller
Hello there,This is me Ran Bahadur B.K., A graduated computer engineer. I have 3+ years of work experience in wordpress design and development. I have strong knowledge of HTML, CSS and PHP which are the three ingredients of web development. Currently i am working with the software company so i also have experience in desktop apps and mobile apps development.

Latest

Python

How to Create Login Application in Python using SQLite Database?

How to use View Binding in Android?

Windows 10 Build 1909 Features that you should know.

How to Create a Complete Login and Forgot Password System in java ?

Prev Next 1 of 15
  • About us
  • Contact us
  • Privacy Policy
  • Disclaimer
© 2022 All Rights Reserved.
Website By: Ran Bahadur B.K.