[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Change password login form not working

Posted on 2013-06-25
3
Medium Priority
?
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1500 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 13

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

656 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