Home > Software engineering >  VB to modify the password problem urgent urgent!!!!!
VB to modify the password problem urgent urgent!!!!!

Time:09-16

Private Sub Command1_Click ()
Dim the db As New ADODB. Connection
Dim the rs As New ADODB. You
Dim As SQL String
The ConnectionString="driver={SQL server}; Server=(local); Uid=sa; The PWD=sa; The database=WXCB "
The Open
If the Trim (text2. Text="") Then
MsgBox "old password cannot be empty, please input again!" , vbOKOnly + vbExclamation, "warning"
Text2. Text=""
Text2. SetFocus
The Exit Sub
End the If
If the Trim (Text3. Text="") Then
MsgBox "new password cannot be empty, please input again!" , vbOKOnly + vbExclamation, "warning"
Text3. Text=""
Text3. SetFocus
The Exit Sub
End the If
If Text3. Text & lt;> Text4. Text Then
MsgBox "two enter a new password, please input again!" , vbOKOnly + vbExclamation, "warning"
Text3. Text=""
Text4. Text=""
Text3. SetFocus
The Exit Sub
The Else
SQL="select * from user1 where user name='" & amp; Text1. Text & amp; "'
"Rs. The Open SQL, db, adOpenStatic adLockReadOnly 'Open return record sets available
If the rs. EOF=True Then
MsgBox "without the users" vbOKOnly + vbExclamation, ""
Text1. Text=""
Text2. Text=""
Text3. Text=""
Text4. Text=""
Text1. SetFocus
The Else
If the Trim (rs) Fields (" password ")) & lt;> Trim (text2. Text) Then
MsgBox "old password is wrong, please input again!" , vbOKOnly + vbExclamation, "warning"
Text2. Text=""
Text3. Text=""
Text4. Text=""
Text3. SetFocus
The Else

MsgBox "the password is changed!" , vbOKOnly + vbInformation, "tip"
Text1. Text=""
Text2. Text=""
Text3. Text=""
Text4. Text=""
Text1. SetFocus
End the If
End the If
End the If
Rs. Close
Set the rs=Nothing
End Sub

Show the password change is successful, but the data did not change

CodePudding user response:

Didn't see the update from the beginning to the end

CodePudding user response:

Then how to in MsgBox "password is changed!" , vbOKOnly + vbInformation, "tips" on how to add?

CodePudding user response:

Much more accumulate knowledge ah,,,
http://www.w3school.com.cn/sql/sql_update.asp
The UPDATE table name SET column names=new value WHERE the column name=a

UPDATE user1 SET your password column name=new password WHERE the content of the username=TXT

CodePudding user response:

I added the Update in the way you user1set password=text3. Textwhere username=text1. Text display method was not found or data member

CodePudding user response:

refer to the second floor qq2238916 response:
that how should the MsgBox "password is changed!" , vbOKOnly + vbInformation, "tips" on how to add?


Don't know what are your database fields, the password is which a field (or specific field name),
I don't have a practical application of the ADODB library object,

But it seems I can still give you some reference opinions (some not sure where you need to "test"),
First of all, you rs. Open after the success of the execution, rs. RecordCount value should be 1
If more than 1, that means there are multiple records (" user name "is repeated in the database),

Second, when the rs. RecordCount to 1, do you want to modify the corresponding user "password", should be used:
Rs. Fields (key). Value="new password" https://bbs.csdn.net/topics/
The "key" how to use here, you need to have a try, do not rule out "two methods are good" below may) :
1. Can see use value, "password" is which a field (in which), just a few,
Such as the field is the ID, the user name, nickname, password, E-mail, then the key should be 4 (and possibly 3),
You can set a breakpoint, with msgbox or debug. Print statement "view" confirm beforehand,
2. If you can't use value, then it should use the name "field",
Such as just now, for example, the field structure of may so you can change: rs. Fields (" password "). The Value="new https://bbs.csdn.net/topics/password
". Of course, the rs RecordCount is greater than 1, so you can modify a specific user password:
Rs (recordset object) have several ". MoveXXXX "method, the" of "the current record pointer moved to the specified record,
Just said above "modify" operations, is aimed at "the current record is modified,

Modify the data, to "submit", is a call (don't pass any parameters) : rs. Update

CodePudding user response:

In reply, just now see the parameter under "Update",
Executed after the success, perhaps on rs. Open the line:
Rs. The Update "password", "new password"

And, of course, does not rule out the first parameter to preach the "value" may (according to the above reply in 1. The method to confirm specific value),

CodePudding user response:

Don't put the new password is written to the database

CodePudding user response:

.
Db. Execute the UPDATE "user1 SET [code]='" & amp; Trim (Text3. Text) & amp; "' WFERE [username]='" & amp; Text1. Text & amp; "' AND [code]='" & amp; Trim (text2. Text) & amp; "'
"MsgBox "the password is changed!" , vbOKOnly + vbInformation, "tip"
.

In addition If Trim (Text3. Text="") Then should be the If the Trim (Text3. Text)=" "Then

CodePudding user response:

After the search can be directly modified, as follows:
 
The Else
Rs. Fields (" password ")=trim (Text3. Text)
Rs. Updata
MsgBox "the password is changed!" , vbOKOnly + vbInformation, "tip"

CodePudding user response:

Don't change the password of the SQL statement: hello

CodePudding user response:

The above statement rs. Fields (" password ")=trim (Text3. Text), there must be, do,

CodePudding user response:

In MsgBox "password is changed!" , vbOKOnly + vbInformation, "tip" statement must be change the password before

Rs. Fields (" password ")=trim (Text3. Text)
Rs. The Update
  • Related