Syntax error in the FROM clause

1

I have 2 questions on a single topic. The following function works on other developments normally.

Public Function VerificaUsr(ID As String, Psw As String) As Boolean
    Dim Rslt As Boolean

    Rslt = Conectar()
    If Not Rslt Then Exit Function

    DBCmd.CommandText = "SELECT * FROM User WHERE Login_Name='" + ID + "' And Password='" + Psw + "'"
    DBCmd.Connection = Conn

    Reader = DBCmd.ExecuteReader
    If Reader.Read Then
        Return True
    Else
        nEnt = nEnt + 1
        If nEnt > 2 Then
            MessageBox.Show("Ha excedido los intentos de Acceso!", "Acceso sistema de Transporte", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Application.Exit()
        End If
        MessageBox.Show("ID de usuario y/o clave de acceso incorrectos", "Acceso sistema de Transporte", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Return False
    End If
    Conn.Close()
End Function

As you can see it is to guarantee that the user who tries to enter the system is valid. But in a new development (With the same characteristics as others - Same computer and same version of Access) I get the following error:

  

Syntax error in the FROM clause

in line Reader = DBCmd.ExecuteReader and in Access that instruction works well, what do you think happens?

The other: The "End Function" tells me that the function does not return a value.

I appreciate any help or idea.

    
asked by Maximiliano Gil Toro 21.03.2018 в 05:52
source

1 answer

1

Regarding your second question, you have this line

If Not Rslt Then Exit Function

In that case, you are not effectively returning any value. You should modify it by:

If Not Rslt Then Return False;

As for the first, User is a Access reserved word , so in that case if User is the name of the table, it must be enclosed in square brackets. Try with:

DBCmd.CommandText = "SELECT * FROM [User] WHERE Login_Name='" + ID + "' And Password='" + Psw + "'"
    
answered by 21.03.2018 в 10:47