1

Does anything look wrong with this statement? I can't find anything wrong with it...

UPDATE AccountInfo
SET First Name = 'Test', Last Name = 'Account', Street = 'Street', State = 'State', ZipCode = 55555
WHERE id = 1

I'm writing a VB program, and I'm implementing an edit feature. This is the problem code.

        Public Function updateAccountInfo(ByVal cp As CPerson, ByVal fName As String, ByVal lName As String, ByVal address As String, ByVal state As String, ByVal zip As Integer) As Boolean
    Dim sql, sql2 As String
    sql = "UPDATE AccountInfo SET First Name = '" & fName & "', Last Name = '" & lName & "', Street = '" & address & _
        "', State = '" & state & "', ZipCode = " & zip & " WHERE id = " & cp.returnIDOnlyNumber
    sql2 = "UPDATE Accounts SET First Name = '" & fName & "', Last Name = '" & lName & "' WHERE id = " & cp.returnIDOnlyNumber
    Return do_command(sql, sql2)
End Function

Private Function do_command(ByVal sql As String, ByVal sql2 As String) As Boolean
        Dim command As OleDbCommand
        Try
            conn.Open()
            command = New OleDbCommand(sql, conn)
            command.ExecuteNonQuery()
            conn.Close()
            conn.Open()
            command = New OleDbCommand(sql2, conn)
            command.ExecuteNonQuery()
            conn.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
2
  • 1
    I guess ZipCode is string. Commented Dec 17, 2014 at 12:44
  • Are you using mySql? Commented Dec 17, 2014 at 12:44

1 Answer 1

5

Yes, you have space in the names. If you really have them, then you need to escape them, perhaps with square braces:

UPDATE AccountInfo
    SET [First Name] = 'Test', 
        [Last Name] = 'Account',
        Street = 'Street',
        State = 'State',
        ZipCode = '55555'
WHERE id = 1;

It is better to have names with no spaces. Also, the zip code should be stored as a string, not a number, otherwise you will lose leading zeros.

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

2 Comments

I haven't had issues using spaces in INSERT statements.
Never mind. Looks like taking out the spaces fixed it. That and I changed the zip to String. I forgot zip codes can start with 0's.

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.