Can anyone please help me , I am currently designing a small school project now my problem is I have done access tables and did connect these tables to my VB forms but now I want to code for the button login, I want to use the information that is in my databases (table PASSWORDS) for username and password but I don't know how to retrieve this information…. PLEASE HELP ME

Here is the code. You need 2 TextBoxes, 1 Button and 1 ErrorProvider Control on your Login Form. I've used a MySQL database, you may use whatever suits you.

Public Class Login

    Dim cn As New Odbc.OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=mydrupaldb; User=root;Password=;")

    Private Sub login_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    End Sub

    Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Button1.Enabled = False

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'Define the SQL Command to retrieve records from the database
        Dim cmd As New Odbc.OdbcCommand("select * from users where name=? and pass=?", cn)

        cmd.Parameters.Add("@name", Odbc.OdbcType.VarChar, 60)
        cmd.Parameters("@name").Value = Me.TextBox1.Text

        cmd.Parameters.Add("@pass", Odbc.OdbcType.VarChar, 32)
        cmd.Parameters("@pass").Value = Me.TextBox2.Text

        'We have a Data Reader to read the values returned by the SQL Command Execution
        Dim dr As Odbc.OdbcDataReader
        dr = cmd.ExecuteReader

        'Check if username and password exist. 

        If dr.HasRows = True Then
            'If exists, then we show the next form which contains the application, in my case its Form1

            ' Incorrect Login Details Supplied
            Me.ErrorProvider1.SetError(Me.Button1, "Incorrect Login...Try again")
            Me.Button1.Enabled = False
        End If

    End Sub

    Private Sub TextBox2_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.LostFocus
        Me.Button1.Enabled = True
    End Sub

If you have stored your passwords in the database in MD5 encryption (which is generally preferable), you can find the code for that here-

This article has been dead for over six months. Start a new discussion instead.