Solved

Change password login form not working

Posted on 2013-06-25
3
402 Views
Last Modified: 2013-06-26
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
0
Comment
Question by:ernie_shah
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39276049
I suspect that following line is throwing the error

 If OldPassword.Text = reader("Password").ToString() Then

I would change your code

        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()

Open in new window


to following


        con.Open()
        str = "select IsNull(Count(*), 0) from login Where UserName=@Username AND Password=@Password"
        com = New SqlCommand(str, con)
        com.Parameters.AddWithValue("@Username", Username.Text)
        com.Parameters.AddWithValue("@Password", OldPassword.Text
        up = com.ExecuteScalar()
        con.Close()

Open in new window

0
 
LVL 12

Expert Comment

by:jitendra patil
ID: 39277200
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.
0
 

Author Comment

by:ernie_shah
ID: 39278240
The error is generated at con.open ()
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now