WHAT'S NEW?
Loading...

Login System in VB.NET

DataBinding approach and MS Access to access the data from your database source.


This is the user login. Your be able to login if you have already an account stored in database or you may create a new one, but the username check if it is already exists or not. The program does not automatically store your new account unless you could not create a new one.
Public Class UserLogin

    Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
        Dim login = TbluseraccountTableAdapter1.ScalarQueryLogin(txtusername.Text, txtpassword.Text)
        If login Is Nothing Then
            MessageBox.Show("Invalid Username or Password")
        Else
            MsgBox("Welcome")
        End If
    End Sub

    Private Sub linkcreateaccount_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles linkcreateaccount.LinkClicked
        Add_new_account.ShowDialog()
    End Sub
End Class

Create new account for the user:


Create Username and Password. Make sure that the password is match to another textbox which is confirming password.
Public Class Add_new_account

    Private Sub btnsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim checkuser = TbluseraccountTableAdapter1.ScalarQuerycheck(txtusername.Text)
        If checkuser Is Nothing Then
            If txtpasswordconfirm.Text = txtpassword.Text Then
                TbluseraccountTableAdapter1.InsertQueryUser(txtusername.Text, txtpassword.Text)
                MessageBox.Show("New user added to your database")
            Else
                MessageBox.Show("Password not match")
            End If
        Else
            MessageBox.Show("Username is already exists")
        End If
    End Sub
End Class
Here is the quick and simple Video Tutorial how to Login in VB.NET.

This is the DataSet where you can query using the TableAdapter 


                Here are the following Query:


Fill, GetData() 'it's already given
SELECT ID, Username, [Password] FROM tbluseraccount

InsertQueryUser (Username,Password)
INSERT INTO tbluseraccount
                         (Username, [Password])
VALUES        (?,?)

ScalarQuerycheck(Username)
SELECT        COUNT(*) AS Expr1, Username AS UsernameResult
FROM            tbluseraccount
GROUP BY Username
HAVING        (Username = ?)

ScalarQueryLogin (Username,Password)
SELECT        COUNT(*) AS Expr1, Username AS UsernameResult, [Password] AS PasswordResult

FROM            tbluseraccount
GROUP BY Username, [Password]
HAVING        (Username = ?) AND ([Password] = ?)

4 comments: Leave Your Comments