hi, i debug it keeps show: Syntax error in FROM clause.
i google and read many website tried remove ' ' from sql line still cannot.

can anyone help pls

Public Class frmLogin
    Dim mypath = Application.StartupPath & "\password.mdb"
    Dim Password = ""
    Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Users\Du\Documents\password.mdb")
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader
    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub

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


        Dim sql = "SELECT Username,Password FROM Password WHERE Username = '" & txtUserName.Text & "' AND Password = '" & txtPassword.Text & "'"
        Try
            conn.Open()

            cmd = New OleDbCommand(sql, conn)
            Dim dr As OleDbDataReader = cmd.ExecuteReader

        Catch ex As InvalidOperationException
            MsgBox(ex.Message)

        End Try
        Try
            If dr.Read = False Then
                MessageBox.Show("Authentication Failed...")
            Else
                MessageBox.Show("Login Successful...")

            End If
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

        If conn.State <> ConnectionState.Closed Then
            conn.Close()

i just realized what i gave you is exactly what you have...sorry

Edited 6 Years Ago by Elehas: n/a

I'm not sure but having one of the fields in your table the same name as the table name that it is in is a good idea. If you really cannot change the name of the field in your table then try referencing the fields directly using Password.Username and Password.Password

Hope this helps

ParkeyParker

now when i click on button, it shows error: object reference not set to an instances of an object.

by the way to create access db, just need to fill one column call Username another call Password right, how about the datatype? my username field data is 7654321a (text) while password data is 12345678 (number) i suppose

Imports System.Data.OleDb

Public Class frmLogin
    Dim mypath = Application.StartupPath & "\password.mdb"
    Dim Password = ""
    Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Users\Du\Documents\password.mdb")
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader

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

        Dim sql = "SELECT Username,Password FROM login WHERE Username = '" & txtUserName.Text & "' AND Password = '" & txtPassword.Text & "'"
        Try
            conn.Open()

            cmd = New OleDbCommand(sql, conn)
            Dim dr As OleDbDataReader = cmd.ExecuteReader

        Catch ex As InvalidOperationException
            MsgBox(ex.Message)

        End Try
        Try

            If dr.Read = False Then
                MessageBox.Show("Authentication Failed...")
            Else
                MessageBox.Show("Login Successful...")

            End If
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

        If conn.State <> ConnectionState.Closed Then
            conn.Close()
        End If

    End Sub

End Class

Edited 6 Years Ago by gu0gu0: n/a

This question has already been answered. Start a new discussion instead.