Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.net strange error in Update query

Hi

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)


        Try


            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
            cn.Open()

            cmd.ExecuteNonQuery()

        Catch ex As Exception
            Response.Write(ex.Message)
        Finally
            If cn.State <> ConnectionState.Closed Then
                cn.Close()
            End If
        End Try
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

thanks very much for the help