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

Recommended Answers

All 12 Replies

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

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.

commented: N.A -4

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...

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...

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

str="update login set [password]=?"
commented: Misguidance +0

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.

commented: Don't misguide please. -3

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

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

thnx a ton tht worked fine.....

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

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

commented: Providing incorrect misleading information +0

Read post #10.

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

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.