I use below code to update to access 2003 from resetting password of login but when I use sql command to select pw, it still same pw, why????
Please help :-(
VB.NET:
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
Dim sqlconn As New OleDbConnection
Dim cmd As OleDbCommand = Nothing
Dim transaction As OleDbTransaction
Dim m As Match = regex.Match(Me.txtReset.Text)
If Me.txtReset.Text = "" Then
MsgBox("Password cannot be empty", MsgBoxStyle.Information)
Me.txtReset.Focus()
Exit Sub
End If
If Not m.Length = txtReset.Text.Length Then
MsgBox("Password contains invalid characters", MsgBoxStyle.Information)
Me.txtReset.Focus()
Exit Sub
End If
'sqlconn.ConnectionString = connString
sqlconn = New OleDbConnection(connString)
sqlconn.Open()
Try
Dim sqltxt As String
sqltxt = "UPDATE tblLogin SET pw = @inPassword, active = @act WHERE userId = @inUId"
'Dim trans as new OleDBTransaction = sqlconn.BeginTransaction
transaction = sqlconn.BeginTransaction()
Dim crPW As String
crPW = encryptor.Encrypt(txtReset.Text)
cmd = New OleDbCommand(sqltxt, sqlconn)
cmd.Connection = sqlconn
cmd.Transaction = transaction
cmd.Parameters.AddWithValue("@inUId", uid)
cmd.Parameters.AddWithValue("@inPassword", encryptor.Encrypt(txtReset.Text))
cmd.Parameters.AddWithValue("@act", True)
cmd.CommandText = sqltxt
cmd.ExecuteNonQuery()
transaction.Commit()
Dim cmd2 As OleDbCommand
cmd2 = sqlconn.CreateCommand
cmd2.CommandText = "select pw, active from tblLogin where userid ='admin'"
'cmd.CommandText = sqltxt
'cmd.CommandType = CommandType.Text
rdr = cmd2.ExecuteReader
rdr.Read()
MessageBox.Show(rdr.GetString(0))
MessageBox.Show(rdr.GetBoolean(1))
MessageBox.Show("PW was reset successful!")
Catch ex As SqlException
'transaction.Rollback()
sqlconn.Close()
MessageBox.Show("Transaction unsuccesfull, it has been rolled back.")
Exit Sub
End Try
transaction.Dispose()
sqlconn.Close()
fLogin.Show()
Me.Hide()
Please help :-(