0

I've been struggling to figure this one out, and keep running into the same issue. I have an Access database that has linked Excel Files. The title of the excel file is Store # and the pound symbol is where I'm running into issues.

New OleDbCommand("SELECT * FROM LSM WHERE Store # = @Store", myConnection)
    lstscmd.Parameters.AddWithValue("@Store", CInt(gateDBSearch))

If I remove the # symbol, and remove it in my code it works (The richtexbox shows only the result for the record searched), unfortunately this isn't an option in the final version. If I leave the # symbol in the file, but remove it from the code, the richtextbox fills with all of the results. If I leave the # symbol on both the code and file I get a Syntax error in date in query expression 'Store # = @Store' exception. Any help on this would be great.

Dim lstscmd As OleDbCommand = New OleDbCommand("SELECT * FROM LSM WHERE Store # = @Store", myConnection)
        lstscmd.Parameters.AddWithValue("@Store", CInt(gateDBSearch))
        dr = lstscmd.ExecuteReader
        While dr.Read()

            txtRichInfo.AppendText(dr("Gate Tech").ToString + Environment.NewLine)
            lblAccessSysChange.Text = dr("Access System").ToString

        End While

        myConnection.Close()
        lblAccessSysChange.Visible = True

1 Answer 1

1

Because your field name contains special characters, you need to wrap it in square brackets to tell the SQL parser that it's all one name.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! A co-worker and I kept on trying every different thing and couldn't get it to work. This worked perfectly!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.