Syntax error in UPDATE statement
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:
- Dim dt As DataTable = dsUsers.Tables("Users")
- If State = FormState.adStateAddMode Then
- ' add a row
- Dim newRow As DataRow
- newRow = dt.NewRow()
- dt.Rows.Add(newRow)
- End If
- With dt
- .Rows(0)("UserID") = txtUsername.Text
- .Rows(0)("Password") = txtPassword.Text
- .Rows(0)("CompleteName") = txtCompleteName.Text
- .Rows(0)("Admin") = changeYNValue(CStr(Check1.CheckState))
- daUsers.Update(dsUsers, "Users")
- 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.
Comments
Password Setting
update record
Add new comment
- Add new comment
- 88 views