syntax error in update statement

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2009
Posts: 136
Reputation: babbu has a little shameless behaviour in the past 
Solved Threads: 14
babbu babbu is offline Offline
Junior Poster

syntax error in update statement

 
-2
  #1
Sep 20th, 2009
this is my code
  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
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,285
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 586
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: syntax error in update statement

 
0
  #2
Sep 20th, 2009
It might help if you posted the exact error message and indicated what database you were using
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 307
Reputation: TomW is on a distinguished road 
Solved Threads: 44
TomW TomW is offline Offline
Posting Whiz

Re: syntax error in update statement

 
-1
  #3
Sep 20th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 25
Reputation: CodeDoctor is an unknown quantity at this point 
Solved Threads: 6
CodeDoctor's Avatar
CodeDoctor CodeDoctor is offline Offline
Light Poster

Re: syntax error in update statement

 
0
  #4
Sep 22nd, 2009
Originally Posted by babbu View Post
this is my code
  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:
  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...
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 136
Reputation: babbu has a little shameless behaviour in the past 
Solved Threads: 14
babbu babbu is offline Offline
Junior Poster

Re: syntax error in update statement

 
-1
  #5
Sep 24th, 2009
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...
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,689
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 481
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: syntax error in update statement

 
0
  #6
Sep 24th, 2009
Field name password is a access's reserved word.
Use,
  1. str="update login set [password]=?"
Last edited by adatapost; Sep 24th, 2009 at 3:09 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 307
Reputation: TomW is on a distinguished road 
Solved Threads: 44
TomW TomW is offline Offline
Posting Whiz

Re: syntax error in update statement

 
-1
  #7
Sep 24th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 136
Reputation: babbu has a little shameless behaviour in the past 
Solved Threads: 14
babbu babbu is offline Offline
Junior Poster

Re: syntax error in update statement

 
0
  #8
Sep 24th, 2009
Originally Posted by adatapost View Post
Field name password is a access's reserved word.
Use,
  1. str="update login set [password]=?"
thnx a ton tht worked fine.....
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,285
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 586
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: syntax error in update statement

 
0
  #9
Sep 24th, 2009
Please mark this thread as solved (since adatapost answered your question ) and good luck!
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,689
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 481
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: syntax error in update statement

 
0
  #10
Oct 2nd, 2009
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.aspfa...-keywords.html
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC