none
The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect. ERROR RRS feed

  • Question

  • I tried all possible syntax for the Select Statement but it keeps giving the same error. I'm using VB 2010 and Access 2010.

    Here is the codes I have:

    Dim found As Boolean
            Try
                mm = New OleDb.OleDbCommand
                With mm
                    mm.Connection = nn
                    mm.CommandType = CommandType.Text
                    mm.CommandText = "SELECT FROM Camper ([CLName] = '" & TextBox1.Text & "',[CFName] = '" & TextBox2.Text & "')"
                    nn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\HVP.accdb"
                    nn.Open()
                    r = mm.ExecuteReader
                End With
                While r.Read()
                    nn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\HVP.accdb"
                    nn.Open()
                    r.Read()
                    TextBox3.Text = r("@CCampLevel").ToString
                    TextBox4.Text = r("@CCampSubLevel").ToString
                    If found = True Then
                        TextBox3.Text = r("@CCampLevel").ToString
                        TextBox4.Text = r("@CCampSubLevel").ToString
                        MsgBox("Camper found.")
                    End If
                End While

                Exit Sub
                If found = False Then MsgBox("Camper not found.", MsgBoxStyle.Critical)
                r.Close()
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Critical)
                nn.Close()
            End Try

    Saturday, November 25, 2017 10:58 PM

All replies

  • You forgot to include the columns you're selecting (or just a * wildcard to select all columns):

    SELECT * FROM Camper ....


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Sunday, November 26, 2017 5:12 PM
  • Also, you really should use Parameters instead of inlining from user-provided data (i.e. TextBox) to prevent the possibility of SQL Injection (https://en.wikipedia.org/wiki/SQL_injection).

    ' Note that for Access, parameters are positional and simply specified with a ?
    mm.CommandText = "SELECT * FROM Camper ([CLName] = ?,[CFName] = ?)"
    ' The order they are added to the parameters collection is important because they're positional
    ' The Parameter name ("@CLName" for example), isn't important other than for readability
    mm.Parameters.AddWithValue("@CLName", TextBox1.Text)
    mm.Parameters.AddWithValue("@CFName", TextBox2.Text)

    The parameter usage in the query would be different if you were using SQL Server rather than Access (using the actual parameter name instead of the question mark), since parameters are not positional in SQL Server.


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com



    Sunday, November 26, 2017 5:27 PM