Login form VB.Net

In my previous article I mentioned how you can make login form in VB6,In this article I will show you how you can make database driven login form in VB.Net with SQL Server 2000 database at backend.

Here you will find it very easy and less time consuming in VB.Net as compare to VB6 because you don’t have to spend much time in the design of the form just have a close look at the following steps:


Step 1:  Adding a built in login form:

Right click on your project name at solution explorer window go to Add and select New Item as shown in the following screen shot:




Add New Item




Now a window appears to Add a New Item here you will select a Login Form as shown in the following screen shot:




Add New Item




Following screen shot will show you how the form looks like:


Login Form


Step 2:  Adding Connection String:

You can have a look at my previous post on How to connect Vb.net to SQL Server 2000 if you want to have look on the connection details.

Here I will use a module for specifying connection string,In order to Add a module repeat same steps which you have adopted while adding a login form but now you have to select “module” instead of  “login form”, see the below screen shot:




Add Module




After clicking the Add button a file having .vb extension will appear in your solution explorer window as shown in the following picture:




Solution Explorer




Now double the connection.vb file and write following code:

Friend DBConnection As String = "PROVIDER=SQLOLEDB;PASSWORD=password;PERSIST SECURITY INFO=true;USER ID=user name;INITIAL CATALOG=database name;DATA SOURCE=hostname/server IP"


Step 3:  Credentials Validation:

Now double click the OK button of the “Login Form” and write following code:

Dim username As String


Dim password As String


Dim recrdsetlogin As New ADODB.Recordset


Dim mycommand As New ADODB.Command


Dim Conn As New ADODB.Connection




    mycommand.CommandText = "select * from usermanagement where username ='" & UsernameTextBox.Text & "' and pasword='" & PasswordTextBox.Text & "'"


    recrdsetlogin.Open(mycommand.CommandText, DBConnection, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly, -1)




    If recrdsetlogin.EOF = True Then


        MsgBox("Sorry User Name Or Passord Is Incorrect")


    ElseIf recrdsetlogin.EOF = False Then


        username = UsernameTextBox.Text


        password = PasswordTextBox.Text






    End If


Catch ex As Exception




End Try



Tagged: , , , , ,
  • Prashant

    i want to all the commands of vb to make an application software.

  • http://www.floodtechs.com water damage restoration

    Should a custom data table be used for this or the standard asp datasets? good article.

    • http://codereflex.net Syed Asad Ahmed

      standard datasets

  • esai

    hi, i am having trouble displaying my registration form after clicking the register button. the registration form is in a try catch code. It showed at first debug , but after debugging again , it only shows the same log in form:
    here is my code for the registration form;
    Label1.Text = “” End If End Sub
    Private Sub ButtnReg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtnReg.Click Try My.Settings.Username = TextBox1.Text My.Settings.Password = TextBox2.Text My.Settings.Confirm = TextBox3.Text My.Settings.Status = True My.Settings.Save() MsgBox(“You have successfully registered”, 1, Title:=””) Application.Restart() Catch ex As Exception
    End Try MsgBox(” Couldn’t create account, try again”) End SubEnd Class

    my register button is in the log in form, i want to show the register form after I have clicked
    the register button;

    here is the code I made;

    Private Sub regbttnlog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles regbttnlog.Click Dim form As New registrationform form.Show() Me.Close() form = Nothing

    Pls..I really need this for our school project, i need help badly…

    best regards!