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
        cn.Close()
    End Sub

    Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cn.Open()
        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
            Form1.Show()

        Else
            ' Incorrect Login Details Supplied
            Me.ErrorProvider1.SetError(Me.Button1, "Incorrect Login...Try again")
            Me.TextBox1.Clear()
            Me.TextBox2.Clear()
            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
        Me.ErrorProvider1.Clear()
    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- http://dotnet.tekyt.info/?p=24

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.