943,696 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 2133
  • VB.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 20th, 2009
-2

syntax error in update statement

Expand Post »
this is my code
VB.NET Syntax (Toggle Plain Text)
  1. If Me.txtOldPassword.Text = pwd Then
  2. Dim oledbcom1 As New OleDb.OleDbCommand
  3. oledbcom1.CommandText = "Update login Set password = ?"
  4.  
  5. oledbcom1.Connection = oledbcon
  6.  
  7. oledbcom1.Parameters.Add("?", OleDb.OleDbType.VarChar)
  8. oledbcom1.Parameters(0).Value = Me.txtNewPassword.Text.Trim
  9.  
  10. oledbcom1.ExecuteNonQuery()
  11.  
  12. oledbcon.Close()
  13. end if
Similar Threads
Reputation Points: -1
Solved Threads: 23
Posting Whiz in Training
babbu is offline Offline
207 posts
since Jun 2009
Sep 20th, 2009
0

Re: syntax error in update statement

It might help if you posted the exact error message and indicated what database you were using
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Sep 20th, 2009
-1

Re: syntax error in update statement

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.
Reputation Points: 84
Solved Threads: 48
Posting Whiz
TomW is offline Offline
342 posts
since Sep 2009
Sep 22nd, 2009
0

Re: syntax error in update statement

Click to Expand / Collapse  Quote originally posted by babbu ...
this is my code
VB.NET Syntax (Toggle Plain Text)
  1. If Me.txtOldPassword.Text = pwd Then
  2. Dim oledbcom1 As New OleDb.OleDbCommand
  3. oledbcom1.CommandText = "Update login Set password = ?"
  4.  
  5. oledbcom1.Connection = oledbcon
  6.  
  7. oledbcom1.Parameters.Add("?", OleDb.OleDbType.VarChar)
  8. oledbcom1.Parameters(0).Value = Me.txtNewPassword.Text.Trim
  9.  
  10. oledbcom1.ExecuteNonQuery()
  11.  
  12. oledbcon.Close()
  13. end if

I am going to suggest you name the params.

Ex:
VB.NET Syntax (Toggle Plain Text)
  1. oledbcom1.CommandText = "Update login Set password = @Password"
  2.  
  3. oledbcom1.Parameters.Add("@Password", OleDb.OleDbType.VarChar).Value = Me.txtNewPassword.Text.Trim


Hope this Helps...
Reputation Points: 10
Solved Threads: 6
Light Poster
CodeDoctor is offline Offline
25 posts
since Sep 2009
Sep 24th, 2009
-1

Re: syntax error in update statement

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...
Reputation Points: -1
Solved Threads: 23
Posting Whiz in Training
babbu is offline Offline
207 posts
since Jun 2009
Sep 24th, 2009
0

Re: syntax error in update statement

Field name password is a access's reserved word.
Use,
VB.NET Syntax (Toggle Plain Text)
  1. str="update login set [password]=?"
Last edited by adatapost; Sep 24th, 2009 at 3:09 am.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Sep 24th, 2009
-1

Re: syntax error in update statement

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.
Reputation Points: 84
Solved Threads: 48
Posting Whiz
TomW is offline Offline
342 posts
since Sep 2009
Sep 24th, 2009
0

Re: syntax error in update statement

Click to Expand / Collapse  Quote originally posted by adatapost ...
Field name password is a access's reserved word.
Use,
VB.NET Syntax (Toggle Plain Text)
  1. str="update login set [password]=?"
thnx a ton tht worked fine.....
Reputation Points: -1
Solved Threads: 23
Posting Whiz in Training
babbu is offline Offline
207 posts
since Jun 2009
Sep 24th, 2009
0

Re: syntax error in update statement

Please mark this thread as solved (since adatapost answered your question ) and good luck!
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Oct 2nd, 2009
0

Re: syntax error in update statement

Welcome TomW,

Read this - SQL Reserved Words

Quote ...
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.aspfa...-keywords.html
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Help for VS.NET/SQL
Next Thread in VB.NET Forum Timeline: Invalid Operation exception..plz help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC