行中出现错误" adapter = New MySqlDataAdapter(" UPDATE用户SET密码WHERE密码='"& txtpassword.Text&"'")"
我该如何解决?
Private Sub getdbdata()
Try
mysqlconn = New MySqlConnection("server=localhost;username=root;database=bank")
dataset = New DataSet
adapter = New MySqlDataAdapter("UPDATE user SET Password WHERE Password ='" & txtpassword.Text & "'")
adapter.Fill(dataset, "user")
mysqlconn.Open()
reader = command.ExecuteReader
If reader.HasRows Then
Form1.Show()
Me.Visible = False
Else
MessageBox.Show("Password change unsuccessful.")
End If
reader.Close()
mysqlconn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
End Try
End Sub
答案 0 :(得分:0)
主要问题在于update Query.
的语法所以在您的代码中进行此更改:
dataset = New DataSet
adapter = New MySqlDataAdapter("UPDATE user SET Password = '" & txtNewpassword.Text & "' " & _
"WHERE userName = '" & txtuser.Text & "' and " & _
"Password ='" & txtOldpassword.Text & "'")
adapter.Fill(dataset, "user")
现在代码已经完整,它会将密码重置为txtNewpassword中的用户,该用户拥有txtuser
中的用户名和txtOldpassword
中匹配的密码
答案 1 :(得分:0)
Imports MySql.Data.MySqlClient
Public Class Settings
Dim con As New MySqlConnection("host =localhost;user id=root;password=;database=cidb")
Dim cmd As New MySqlCommand
Dim dr As MySqlDataReader
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
con.Open()
cmd.Connection = con
cmd.CommandText = "select * from usertbl where uname='" & user.Text & "'and upassword= '" & Pword.Text & "'"
dr = cmd.ExecuteReader
If dr.HasRows Then
Settings()
Else
MsgBox("Invalid Username or Password!")
End If
End Sub
Private Sub Settings()
Dim con As New MySqlConnection("host =localhost;user id=root;password=;database=cidb")
Dim cmd As New MySqlCommand
con.Open()
cmd.Connection = con
cmd.CommandText = "update usertbl set upassword='" & NewPword.Text & "' where uname= '" & usertxt.Text & "'"
cmd.ExecuteNonQuery()
MsgBox("You're successfully change your Password!")
usertxt.Text = " "
Pwordtxt.Text = " "
Newuser.Text = " "
con.Close()
End Sub