ernie_shah
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.Ol eDb.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").ToStrin g() 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("MainMen u.aspx")
Else
Literal1.Text = "Please enter correct Current password"
End If
End Sub
Please assist
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.Ol
"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").ToStrin
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"
com.ExecuteNonQuery()
con.Close()
Literal1.Text = "Password changed Successfully"
Response.Redirect("MainMen
Else
Literal1.Text = "Please enter correct Current password"
End If
End Sub
Please assist
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The error is generated at con.open ()
please be advised that you need to have proper declaration of your variables.
hope this helps.