Ask Experts Questions for FREE Help !
Ask
    damaxy's Avatar
    damaxy Posts: 6, Reputation: 1
    New Member
     
    #1

    May 20, 2009, 04:47 AM
    change password not working
    hello! I have a code as shown below.. the problem is, the code adding new user is working fine but the code for changing password will not work.. it give error.. I need help?? Somebody? Thanks in advanced..


    Private Sub Update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Update.Click
    Dim connection As New OleDbConnection(My.Settings.ConnectionString)
    Dim cmd As New OleDbCommand
    cmd.Connection = connection
    cmd.Connection.Open()
    cmd.CommandText = "Update Users set User_Name='" & TextBox1.Text & "',Password='" & TextBox2.Text & "'where User_Name='" & TextBox1.Text & "'"
    cmd.ExecuteNonQuery()
    End Sub
    End Class



    Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButton.Click
    Dim connection As New OleDbConnection(My.Settings.ConnectionString)
    Dim com As New OleDbCommand
    com.Connection = connection
    com.Connection.Open()
    com.CommandText = "Insert into Users values('" & TextBox1.Text & "','" & TextBox2.Text & "')"
    com.ExecuteNonQuery()
    MsgBox("User Created Successfully....")
    End Sub
    Perito's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #2

    May 20, 2009, 07:29 AM
    It appears that you must be running into one of the"gotcha's" that we all run into once in a while. I think that in your system, the word "Password" is reserved -- at least that's all I can figure out. I created a small Microsoft Access database to test your code, and Access doesn't like "Password". Change the line to something like this ("Password" becomes "_Password"):

    cmd.CommandText = "Update Users SET User_Name='" & TextBox1.Text & "', _Password='" & TextBox2.Text & "' where User_Name = '" & TextBox1.Text & "'"

    You must also change the column name in the database to "_Password" (or whatever you choose) to match the SQL statement.

    One more thing. Since you're opening the database connection, you really should close it.

    Cmd.Connection.Close()

    And

    Com.Connection.Close()
    damaxy's Avatar
    damaxy Posts: 6, Reputation: 1
    New Member
     
    #3

    May 23, 2009, 04:13 AM
    thanks!! Now the password can be change.. but there is another problem.. I can't figure out the reasons..
    now the login form is not working and the delete user is also not working.. before it was working fine.. and what do you mean by that the "password" is reserved? My codes for login form and delete user form are as below;

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Try
    If (connection.State = ConnectionState.Closed) Then connection.Open()
    cmd = New OleDbCommand("select * from Users where User_Name='" & TextBox1.Text & "' and _Password='" & TextBox2.Text & "'", connection)

    Dim x As Integer
    Dim xx As String
    xx = cmd.ExecuteScalar().ToString
    x = Convert.ToInt32(xx)

    If x = 1 Then
    Me.Hide()
    Main.Show()

    ElseIf x = 1 Then
    Me.Hide()
    Main.Show()

    Else
    MsgBox("Invalid User ID/Password!!", MsgBoxStyle.Critical, "Error")
    TextBox1.Focus()


    End If

    connection.Close()
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    End Try
    End Sub



    Private Sub DelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DelButton.Click

    Dim connection As New OleDbConnection(My.Settings.ConnectionString)
    Dim cm As New OleDbCommand
    cm.Connection = connection
    cm.Connection.Open()

    cm.CommandText = "DELETE from Users WHERE _Password='" & TextBox2.Text & "'"
    cm.ExecuteNonQuery()
    MsgBox("User Deleted...", MsgBoxStyle.Information)
    cm.Connection.Close()
    End Sub
    Perito's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #4

    May 23, 2009, 04:24 AM
    I'm not sure why your logon form is not working. It looks OK to me. Also, the Delete function looks OK, also.

    What do you mean by that the "password" is reserved?
    I mean that the database system, itself, uses the word "password" to mean something special. It's not "a password" that's reserved, it's the word, "password". The writers of the database don't allow reserved words to be used as a column headings. They "reserve" them. Here's a reference:

    http://kb2.adobe.com/cps/180/tn_18050.html

    "Certain words are reserved database words. If you use these words in your SQL statements or in CFML code, for instance, they can cause unexpected behavior. This article provides links to reserved database word lists for various databases. "

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search


Check out some similar questions!

Password change [ 1 Answers ]

Hi there well the problem in that I have just come back from a 4 month tour in the falklands islands and my laptop does not seem to remember the password if I type it it it sez its wrong but I have used the same one for a long time and I use it in a few places and it workes but the weird thing is...

How to change admin password through limited account [ 2 Answers ]

Hi I have window xp installed on my PC . I made limited account for other and made my admin account password protected . But now I forgot my admin password . How can I change administrator password through limited account

I need to change my password [ 21 Answers ]

Hello: I just don't know if it's my router than needs changing or my network. It really doesn't matter because I can't find any place to do it, nohow. I DO find a place on my network page that lets me change my wifi network from or to private or public. When I first chose private, I entered...

Password change forms [ 1 Answers ]

I secured a form in my Access database with the following code: Private Sub Command48_Click() 'Attached to On Click event of Command48 Dim strPasswd strPasswd = InputBox("Enter Password", "Restricted Form") 'Check to see if there is any entry made to input box, or if

Change the administration password on my DI series router? [ 1 Answers ]

DI-525 router: need to change password.


View more questions Search