Link to home
Start Free TrialLog in
Avatar of ernie_shah
ernie_shahFlag for Trinidad and Tobago

asked on

Change password login form not working

I am trying to create a change password form for users to change their passwords.
However, the following error is raised:
Object reference not set to an instance of an object.

The follow is the code attached to the update button

Dim connect As String = "Provider=Microsoft.Jet.OleDb.4.0;" & _
 "Data Source=\\IT\otusers.mdb"

        con.Open()
        str = "select * from login "
        com = New SqlCommand(str, con)
        Dim reader As SqlDataReader = com.ExecuteReader()
        While reader.Read()
            If OldPassword.Text = reader("Password").ToString() Then
                up = 1
            End If
        End While
        reader.Close()
        con.Close()
        If up = 1 Then
            con.Open()
            str = "UPDATE tblUsers SET Userpassword = '" + NewPassword.Text + "' WHERE username ='" + UserName.Text + "' "
            com = New SqlCommand(str, con)
            com.Parameters.Add(New SqlParameter("@Password", SqlDbType.VarChar, 50))
            com.Parameters("@Password").Value = NewPassword.Text
            com.ExecuteNonQuery()
            con.Close()
            Literal1.Text = "Password changed Successfully"
            Response.Redirect("MainMenu.aspx")
        Else
            Literal1.Text = "Please enter correct Current password"
        End If
    End Sub

Please assist
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
in which line of code you are getting this error?

please be advised that you need to have proper declaration of your variables.

hope this helps.
Avatar of ernie_shah

ASKER

The error is generated at con.open ()