Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim Conn As New SqlConnection
Dim sql As String
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim Oldpass As String = ""
Dim Cnnstring As String
Cnnstring = "Data Source=NOEY-PC\SA;Initial Catalog=Project;Persist Security Info=True;User ID=sa;Password=powergurn"
Conn.ConnectionString = Cnnstring
sql = "Select Mem_Pass As oldpass from Member where (Mem_Pass='" & txtPass_.Text & "')"
cmd = New SqlCommand(sql, Conn)
Conn.Open()
dr = cmd.ExecuteReader
dr.Read()
If dr.HasRows Then
Oldpass = (dr.Item("oldpass"))
End If
dr.Close()
If Oldpass <> txtPass_.Text Then
MessageBox.Show("รหัสผ่านเก่าไม่ถูกต้องค่ะ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
ElseIf txtPassnew.Text <> txtPassagain.Text Then
MessageBox.Show("กรุณายืนยันรหัสผ่านใหม่ค่ะ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
Else
sql = "Update Mem_Pass SET pwd='" & txtPass.Text & "'"
Try
With cmd
.CommandType = Data.CommandType.Text
.CommandText = sql
.Connection = Conn
.ExecuteNonQuery()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
End If
MsgBox("เปลี่ยนรหัสผ่านเรียบร้อยแล้วค่ะ")