• We just launched and are currently in beta. Join us as we build and grow the community.

Syntax error in UPDATE statement

QU1KS1

Master
Q Rep
0
0
0
Rep
0
Q Vouches
0
0
0
Vouches
0
Posts
29
Likes
105
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
While I was working with Visual Basic .NET by adding a form to manage user account in my system I found an error called “Syntax error in UPDATE statement”. After figuring out what’s the cause of this error I found out that it was the name of the field that is causing the problem.

In my Users table I have the following fields:

UserID

Password

CompleteName

As you can see all of these fields are valid. The statement to save a record back to its database is:

  1. Dim

    dt As

    DataTable =

    dsUsers.

    Tables

    (

    "Users"

    )

  2. If

    State =

    FormState.

    adStateAddMode

    Then
  3. ' add a row
  4. Dim

    newRow As

    DataRow

  5. newRow =

    dt.

    NewRow

    (

    )

  6. dt.

    Rows

    .

    Add

    (

    newRow)
  7. End

    If

  8. With

    dt
  9. .

    Rows

    (

    0

    )

    (

    "UserID"

    )

    =

    txtUsername.

    Text
  10. .

    Rows

    (

    0

    )

    (

    "Password"

    )

    =

    txtPassword.

    Text
  11. .

    Rows

    (

    0

    )

    (

    "CompleteName"

    )

    =

    txtCompleteName.

    Text
  12. .

    Rows

    (

    0

    )

    (

    "Admin"

    )

    =

    changeYNValue(

    CStr

    (

    Check1.

    CheckState

    )

    )

  13. daUsers.

    Update

    (

    dsUsers, "Users"

    )
  14. End

    With

But when I run the program and update the record, visual basic breaks at this line:

Rows(

0

)

(

"Password"

)

=

txtPassword.

Text

Now, looking back at what I have learned about naming convention I come to think that Password attribute is a reserved word. After changing the name of this attribute from Password to Passworda the error has gone.

This is sometimes very frustrating when you are in a hurry working with your code to meet the deadline. But this is a fact that we have to face to become a successful programmer.

The only ingredient that you need to develop is patience.

 

452,496

335,819

335,827

Top