问题描述
我正在做校园作业,以制作薪资计划,现在我的作业几乎完成了90%。但是在制作密码替换表单时遇到了一个问题,我尝试了各种方法,但是它们不起作用。我正在使用Microsoft Access数据库(mdb)。
对不起,我的英语不好。请帮忙。
这是我的编码:
Private Sub Button1_Click(sender As Object,e As EventArgs) Handles Button1.Click
Call Koneksi()
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
MsgBox("Password masih kosong",vbExclamation + vbOKOnly,"Pesan")
Exit Sub
End If
If TextBox3.Text <> TextBox2.Text Then
MsgBox("Password konfirmasi salah")
TextBox3.Focus()
Else
If MessageBox.Show("Yakin akan ganti Password..?","",MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Dim sqlCMD As New OleDbCommand
sqlCMD.Connection = DataBase
sqlCMD.CommandType = CommandType.Text
sqlCMD.CommandText = "UPDATE Pengguna set Password = '" & TextBox2.Text & "' where Kode_Pengguna = '" & Label4.Text & "'"
sqlCMD.ExecuteNonQuery()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
Me.Close()
Else
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
Me.Close()
End If
End If
End Sub
解决方法
您的麻烦很可能是因为 password 是Access中的保留字。因此,请尝试使用方括号:
SqlCMD.CommandText = "update Pengguna set [Password] = '" & TextBox2.Text & "' where Kode_Pengguna = '" & Label4.Text & "'"