Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
string query = "update DefaultProfile set Password='abc123' where RegNo='admin'";

can somebody please tell me what is the problem in the above query for an access database table.
table name : DefaultProfile

There are 4 columns in that table with the names: RegNo, Password, Course & Name.
I need to update the Password field but when I execute this query with an OledbCommand for access Connection, c# throws a syntax error for this update query.

I can't figure out what is the the problem in the syntax.

[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 5-Sep-14 1:37am
v2
Comments
OriginalGriff 5-Sep-14 7:38am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously.
Member 11040029 5-Sep-14 7:39am    
I did not really know that..thnx..but where was a word like that...please let me know

Use below query

string query = "update DefaultProfile set [Password]='abc123' where RegNo='admin'";
 
Share this answer
 
Comments
Member 11040029 5-Sep-14 7:43am    
Thank you for such early and helpful reply.
"Password" is a reserved word: you need to escape it:
C#
string query = "update DefaultProfile set [Password]='abc123' where RegNo='admin'";

But... don't do it like that!
1) Don't pass values to and database as strings, particularly if they may (as these will) originate with the user. Use Parameterised queries instead. passing strings as part of your SQL is an invitation to SQL injection attacks, which can damage or destroy your DB!
2) Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
 
Share this answer
 
Comments
Member 11040029 5-Sep-14 7:43am    
Thank you for such early and helpful reply.
Member 11040029 5-Sep-14 7:44am    
thank you for the link as well
OriginalGriff 5-Sep-14 7:58am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900