Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I solve System.Data.OleDb.OleDbException: 'Syntax error in FROM clause

Imports System.Data.OleDb
Imports System.Data

Public Class Form1
    Dim connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Dimph\OneDrive\Desktop\Richfield BSC IT --- 1st year\Second Semester\Programming 512\Assignment\WinFormsApp1\WinFormsApp1\bin\Debug\net6.0-windows\Database2.accdb")
    '
    Private Sub btnLogin(sender As Object, e As EventArgs) Handles Button1.Click
        If txtUsername.Text = Nothing Or txtPassword.Text = Nothing Then
            MsgBox("Enter Credentials", MsgBoxStyle.Exclamation)
        Else
            If connection.State = ConnectionState.Closed Then
                connection.Open()
            End If

            Dim cmd As New OleDbCommand("select count(*) from User where UserName=? and Password=?", connection)
            cmd.Parameters.AddWithValue("@1", OleDbType.VarChar).Value = txtUsername.Text
            cmd.Parameters.AddWithValue("@2", OleDbType.VarChar).Value = txtPassword.Text
            Dim count = Convert.ToInt32(cmd.ExecuteScalar())

            If (count > 0) Then
                SplashSCreen.Show()
            Else
                MsgBox("Account not found on Database")
            End If
        End If
    End Sub

    Private Sub btnReset(sender As Object, e As EventArgs) Handles Button2.Click

    End Sub

    Private Sub btnSignUp(sender As Object, e As EventArgs) Handles Button3.Click
        Form2.Show()
        Me.Hide()
    End Sub

    Private Sub btnClose(sender As Object, e As EventArgs) Handles Button4.Click
        Me.Close()

    End Sub
End Class

>Solution :

User and Password are both reserved words and using them as object names can confuse the db engine. If you can’t rename them, you can bracket them in your SQL so the db engine understands you’re referring to objects.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

select count(*) from [User] where UserName=? and [Password]=?

Or you could do it this way with fewer brackets:

select count(*) from [User] AS u where u.UserName=? and u.Password=?
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading