Login Form in VB.NET Using Stored Procedure | VB.NET

 


Learn how to create a secure and functional Login Form in VB.NET using a Stored Procedure

This step-by-step tutorial shows you how to:

1.  Login form design


2. Create Database and table 

CREATE TABLE [dbo].[UserMst] (

    [Id]       INT           IDENTITY (1, 1) NOT NULL,

    [Username] NVARCHAR (50) NOT NULL,

    [Password] NVARCHAR (50) NOT NULL,

    PRIMARY KEY CLUSTERED ([Id] ASC)

);

3. Create SP (Store Procedure) for login

CREATE PROCEDURE [dbo].[sp_login]

@un nvarchar(50),

@pwd nvarchar(50)

AS

BEGIN

set nocount on

select * from UserMst where Username=@un and Password=@pwd

END

4. Test SP

       exec sp_login @un=Admin,@pwd=pass 

       exec keyword than SP name than pass parameter

5. Add "Microsoft.Data.SqlClient" NuGet package and Imports Microsoft.Data.SqlClient I have already added

6. Write logic for login button click event

 Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click

     Dim sqlcon As New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Data\Employeedb.mdf;Integrated Security=True")

     Dim sqlcmd As New SqlCommand("sp_login", sqlcon)

     sqlcmd.CommandType = CommandType.StoredProcedure

     sqlcmd.Parameters.AddWithValue("@un", txtUsername.Text)

     sqlcmd.Parameters.AddWithValue("pwd", txtPassword.Text)

     Dim da As New SqlDataAdapter(sqlcmd)

     Dim ds As New DataSet()

     da.Fill(ds)

     If ds.Tables(0).Rows.Count > 0 Then

         btnCancel_Click(sender, e) 'to clear textbox successfull login

         MessageBox.Show("Login Successfull!")

     Else

         MessageBox.Show("Login Fail!")

     End If


 End Sub

7. Write logic for cancel button click event

Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click

    txtUsername.Text = ""

    txtPassword.Text = ""

    txtUsername.Focus()

End Sub

8. Run the application and check



9. If you face any issue please comment below.


🔧 Technologies Used:

  • VB.NET (Visual Basic .NET)

  • Service based database

  • Stored Procedures

  • ADO.NET

  • Visual Studio 2026 (Insider)

  • .NET 10


📌 This video is perfect for beginners and intermediate developers looking to understand database-driven login systems in Windows Forms applications.

👍 Like, Share & Subscribe for more VB.NET tutorials!

💬 Drop your questions in the comments — I’m here to help!



Comments

Popular posts from this blog

Understanding Middleware in .NET Core

Database Approaches in .NET Core: Code-First vs Database-First Explained for Beginners

Dev tunnels