We help IT Professionals succeed at work.
Get Started

ASP.net strange error in Update query

Murray Brown
Murray Brown asked
Last Modified: 2012-05-12

I get an error in the following code
"Incorrect syntax in UPDATE Statement"
If I do exactly the same query in my Access database it works
Is it the Code that I am using
Sub UpdateNewEmailAndPassword(ByVal sEmail As String, ByVal sPassword As String)

        '// define a connection to the database
        Dim cs As String = ConfigurationManager.ConnectionStrings("WhatEverNameYouWant").ConnectionString

        cs = cs.Replace("App_Data\GC.accdb", Server.MapPath("App_Data\GC.accdb"))

        Dim cn As New OleDbConnection(cs)


            Dim sSQL As String
            sSQL = "UPDATE MyUsers SET Password = '" & sPassword & "' WHERE Email = '" & sEmail & "'"
            'sSQL = "INSERT INTO MyUsers ( [Email], [Password], [FirstName], [Logins] ) SELECT '" & sEmail & "' AS Expr1, '" & sPassword & "' AS Expr2, '" & sFirstName & "' AS Expr3, '" & "First login " & CStr(System.DateTime.Today) & " Subsequent logins " & "'"

            '// define the sql statement to execute
            Dim cmd As New OleDbCommand(sSQL, cn)

            '    '// open the connection


        Catch ex As Exception
            If cn.State <> ConnectionState.Closed Then
            End If
        End Try
    End Sub

Open in new window

Watch Question
This problem has been solved!
Unlock 3 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE