Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Creating Login with Change Password: Error There is no row at position 0

$
0
0
All,

I am trying to make a login form for my application and I am having issues with changing the password. Please help me if you can.

Here is what I have tried and failed on:

I have a table that has LoginID, Username, Password

I have written a query in UserLogin Table to gets the old password from DB like this

Code:

SELECT        Username, Password
FROM            UserLoginTbl
WHERE        (Password = @Param1)

and one that updates the password once changed.

Code:

UPDATE      UserLoginTbl
SET            Password = @Password
WHERE        (Username = @Param2)


I have three text boxes on my change password form : OldPassword, NewPasword & ConfirmNewPassword and one Button.

Here is the code in that button:

Code:

Private Sub OkBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OkBtn.Click

        '' validate the new password
        If NewPasswordTxt.Text = "" Then
            MsgBox("Please Enter your new password", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "Human Error")
            NewPasswordTxt.Focus()
            Exit Sub
        End If

        If NewPasswordTxt.Text <> ConfirmPassTxt.Text Then
            MsgBox("The password and Password confirmation entered does not match", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "Human Error")
            NewPasswordTxt.Focus()
            Exit Sub
        End If

        ' get the original password
        Dim TA As New DugsiDBDataSetTableAdapters.UserLoginTblTableAdapter
        Dim DB = TA.GetDataByPassword("Admin")

        If DugsiDBDataSet.UserLoginTbl.Rows.Count > 0 Then
            Dim DBPSW As Integer = DB.Rows(0).Item(2)      ----HERE is where I am GETTING my ERROR

            If DBPSW <> OldPasswordTxt.Text Then
                MsgBox("The old password is incorrect", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "Human Error")
                OldPasswordTxt.Focus()
                Exit Sub
            End If
        End If

        ' everything went well, so we are going to update the password in the db
        Dim Rc As Integer = TA.UpdateDBVar(NewPasswordTxt.Text, "Password")
        If Rc = 0 Then
            MsgBox("Password was not updated", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "Error")
            Exit Sub
        End If
End Sub

With this code I am getthing this error:
indexOutOfRange
There is no row at position 0.

What am I Doing wrong? Please help me if you can.

Thank you in advance.

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>