Update command..plz urgnt
-
Hello All, I make two forms First is Login Form and second is "Change Password" form, when change password form opens here two fields are showed one for OldPassword and other for NewPassword, now my intension is that how i can update an old password in the database (i'm using MSAccess database) tell me the command of Update even i know this command and also apply it but it dosen't work, it gives me error "Syntax error in UPDATE command" on runtime. plz assist me in this way. m.reehanmunir
-
Hello All, I make two forms First is Login Form and second is "Change Password" form, when change password form opens here two fields are showed one for OldPassword and other for NewPassword, now my intension is that how i can update an old password in the database (i'm using MSAccess database) tell me the command of Update even i know this command and also apply it but it dosen't work, it gives me error "Syntax error in UPDATE command" on runtime. plz assist me in this way. m.reehanmunir
that means there is a syntax error at the query string.. just show code and maybe there would be some help.. good coding
-
Hello All, I make two forms First is Login Form and second is "Change Password" form, when change password form opens here two fields are showed one for OldPassword and other for NewPassword, now my intension is that how i can update an old password in the database (i'm using MSAccess database) tell me the command of Update even i know this command and also apply it but it dosen't work, it gives me error "Syntax error in UPDATE command" on runtime. plz assist me in this way. m.reehanmunir
An example of what you are doing will be helpful. Did you remember to put quotes around the passwords? It should look something like this: UPDATE usertable SET password = 'newpassword' WHERE password = 'oldpassword'; When creating the UPDATE string, you will need to surround your password variables with the single quote. That is the only thing I can think of which may be causing the problem. I sometimes find it helpful to use a SQL Editor for creating my SQL statements. It saves me a bunch of time from having to try and retry different commands through code. I don't use MSAccess so I am not sure what type of GUI editor they may have.
-
An example of what you are doing will be helpful. Did you remember to put quotes around the passwords? It should look something like this: UPDATE usertable SET password = 'newpassword' WHERE password = 'oldpassword'; When creating the UPDATE string, you will need to surround your password variables with the single quote. That is the only thing I can think of which may be causing the problem. I sometimes find it helpful to use a SQL Editor for creating my SQL statements. It saves me a bunch of time from having to try and retry different commands through code. I don't use MSAccess so I am not sure what type of GUI editor they may have.
"This is my code now plz help me according to this code" here "password" is the field of database;" OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\C#Projects\\practice1\\SMSDB.mdb;Persist Security Info=False"); con.Open(); string updata = "update SMSDB set password= '"+txtnewpwd.Text+"' where password='"+txtoldpwd.Text+"'"; OleDbTransaction tx = con.BeginTransaction(); tx.Commit(); OleDbCommand cmd = new OleDbCommand(updata,con); cmd.ExecuteNonQuery(); con.Close(); m.reehanmunir
-
that means there is a syntax error at the query string.. just show code and maybe there would be some help.. good coding
"this is my code now plz help me according to this" here "password" is database field;" thx OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\C#Projects\\practice1\\SMSDB.mdb;Persist Security Info=False"); con.Open(); string updata = "update SMSDB set password= '"+txtnewpwd.Text+"' where password='"+txtoldpwd.Text+"'"; OleDbTransaction tx = con.BeginTransaction(); tx.Commit(); OleDbCommand cmd = new OleDbCommand(updata,con); cmd.ExecuteNonQuery(); con.Close(); m.reehanmunir
-
Hello All, I make two forms First is Login Form and second is "Change Password" form, when change password form opens here two fields are showed one for OldPassword and other for NewPassword, now my intension is that how i can update an old password in the database (i'm using MSAccess database) tell me the command of Update even i know this command and also apply it but it dosen't work, it gives me error "Syntax error in UPDATE command" on runtime. plz assist me in this way. m.reehanmunir
It is not necessary to create a transaction. Transactions are used when you plan on doing several SQL calls and there is the possibility of a problem. If there is a problem, a transaction lets you rollback any change prior to anything being fully committed to the database. In the case of the password, you have the one SQL statement and probably do not want it in a transaction. If you did want a transaction, the commit will need to be AFTER your Execute call. As it is, the Transaction in the code is not doing anything and can probably be removed. Try putting a space between password and the '='.