954,164 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

syntax error in update statement

this is my code

If Me.txtOldPassword.Text = pwd Then
                Dim oledbcom1 As New OleDb.OleDbCommand
                oledbcom1.CommandText = "Update login Set password = ?"

                oledbcom1.Connection = oledbcon

                oledbcom1.Parameters.Add("?", OleDb.OleDbType.VarChar)
                oledbcom1.Parameters(0).Value = Me.txtNewPassword.Text.Trim

                oledbcom1.ExecuteNonQuery()

                oledbcon.Close()
end if
babbu
Posting Whiz in Training
208 posts since Jun 2009
Reputation Points: -1
Solved Threads: 23
 

It might help if you posted the exact error message and indicated what database you were using

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

Sknake is right, you need to provide the error message for anyone to provide detailed help other then guessing at whatelse might be going on in your code. For instance, I do not see where you are opening the database connection although you may be doing that elsewhere in the program.

Also is this a single user program, meaning there can be only one person with an account and login? I dont see a where clause in your update query string meaning if there is more then one account, it will update every record in that table.

TomW
Posting Whiz
343 posts since Sep 2009
Reputation Points: 84
Solved Threads: 48
 

this is my code

If Me.txtOldPassword.Text = pwd Then
                Dim oledbcom1 As New OleDb.OleDbCommand
                oledbcom1.CommandText = "Update login Set password = ?"

                oledbcom1.Connection = oledbcon

                oledbcom1.Parameters.Add("?", OleDb.OleDbType.VarChar)
                oledbcom1.Parameters(0).Value = Me.txtNewPassword.Text.Trim

                oledbcom1.ExecuteNonQuery()

                oledbcon.Close()
end if


I am going to suggest you name the params.

Ex:

oledbcom1.CommandText = "Update login Set password = @Password"

                oledbcom1.Parameters.Add("@Password", OleDb.OleDbType.VarChar).Value = Me.txtNewPassword.Text.Trim

Hope this Helps...

CodeDoctor
Light Poster
25 posts since Sep 2009
Reputation Points: 10
Solved Threads: 6
 

the error that i get is
"syntax error in update statement"
with the title..."oledb exception was unhandled"
i am using access 2007 and visual studio 2005
sorry for late reply...

babbu
Posting Whiz in Training
208 posts since Jun 2009
Reputation Points: -1
Solved Threads: 23
 

Field name password is a access's reserved word.
Use,

str="update login set [password]=?"
__avd
Posting Genius (adatapost)
Moderator
8,647 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

I could not get it to work using the '?' as the parameter name. I had to give it an actual name; like CodeDoctor suggested above.

To comment about the above post, "Password" is not a reserved keyword in ms access.

TomW
Posting Whiz
343 posts since Sep 2009
Reputation Points: 84
Solved Threads: 48
 

Field name password is a access's reserved word. Use,

str="update login set [password]=?"


thnx a ton tht worked fine.....

babbu
Posting Whiz in Training
208 posts since Jun 2009
Reputation Points: -1
Solved Threads: 23
 

Please mark this thread as solved (since adatapost answered your question ;)) and good luck!

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

Welcome TomW,

Read this - SQL Reserved Words

SUMMARY: The following list includes all words reserved by the Microsoft Jet database engine for use in SQL statements . The words in the list that are not in all uppercase letters are also reserved by other applications. Consequently, the individual Help topics for these words provide general descriptions that do not focus on SQL usage.

http://sqlserver2000.databases.aspfaq.com/what-are-reserved-access-odbc-and-sql-server-keywords.html

__avd
Posting Genius (adatapost)
Moderator
8,647 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Your link is to Access 2003 but the original poster mentions using a different version (2007).

Access 2007 reserved words and symbols

TomW
Posting Whiz
343 posts since Sep 2009
Reputation Points: 84
Solved Threads: 48
 

Read post #10.

..list includes all words reserved by the Microsoft Jet database engine for use in SQL statements .

__avd
Posting Genius (adatapost)
Moderator
8,647 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Again your first link is to a version the user stated he wasnt using and your second link even confirms it is not a reserved word for the program!

TomW
Posting Whiz
343 posts since Sep 2009
Reputation Points: 84
Solved Threads: 48
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You