Good day guys., im new with vb .net and im currently developing a simple information system for an agency .. im almost done with it but there seem to be a problem with my update statement for the change password code here's my code..,

Imports System.Data.OleDb



Friend Class login
    Public cn As New OleDbConnection
    Public cmd As New OleDbCommand
    Public da As OleDbDataAdapter
    Public dr As OleDbDataReader
    Public ds As DataSet = New DataSet
    Public qry As String = Nothing
    Public conString As String = ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=../data/Philam.mdb")

    Public Sub myCn()
        If cn.State = ConnectionState.Open Then cn.Close()
        cn.ConnectionString = conString
        cn.Open()
    End Sub


    Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox2.PasswordChar = "*"
        Me.CenterToScreen()
        Button3.Hide()
        Label3.Hide()
        TextBox3.Hide()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Or TextBox2.Text = "" Then Exit Sub


        Dim acc As New System.Text.StringBuilder
        acc.AppendLine("SELECT username and password")
        acc.AppendLine("FROM Login WHERE")
        acc.AppendLine("username=@name AND")
        acc.AppendLine("password=@word")

        Try
            Using cn As New OleDbConnection(conString)
                cn.Open()

                Dim cmd As New OleDbCommand(acc.ToString, cn)
                cmd.Parameters.AddWithValue("@name", TextBox1.Text)
                cmd.Parameters.AddWithValue("@word", TextBox2.Text)
                dr = cmd.ExecuteReader
                If dr.HasRows Then

                    Me.Hide()
                    mainForm.Show()
                    TextBox1.Text = ""
                    TextBox2.Text = ""



                Else
                    MsgBox("Invalid username or password", MsgBoxStyle.Exclamation)
                End If
                dr.Close()
            End Using
        Catch ex As Exception
            MessageBox.Show("ERROR" & ex.Message.ToString, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()

    End Sub



    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Button1.Hide()
        Button3.Show()
        Label3.Show()
        TextBox3.Show()

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If TextBox1.Text = Nothing Then
            MsgBox("Please enter your username", MsgBoxStyle.Critical)
            TextBox1.Focus()
        End If

        If TextBox2.Text = Nothing Then
            MsgBox("Please enter your old password", MsgBoxStyle.Critical)
            TextBox2.Focus()
        End If

        If TextBox3.Text = Nothing Then
            MsgBox("Please enter a new password", MsgBoxStyle.Critical)
            TextBox3.Focus()
        End If

        Dim n As String
        Try
            n = (Me.TextBox2.Text)

            Dim accQuery As String = "SELECT * FROM login WHERE username= '" & TextBox1.Text & "' and password='" & n & "'"

            Dim dataset1 As New DataSet
            Dim dataadapter As New OleDbDataAdapter(accQuery, conString)
            dataadapter.Fill(dataset1, "login")

            If Me.BindingContext(dataset1, "login").Count = 0 Then
                MsgBox("The old password is Incorrect", MsgBoxStyle.Critical, "Error")
            Else
                If Me.BindingContext(dataset1, "login").Count > 0 Then
                    Try
                        Dim saveInto As New OleDb.OleDbCommand
                        Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=../data/Philam.mdb"
                        Dim conn As New OleDbConnection(conStr)
                        saveInto.Connection = conn
                        saveInto.CommandType = CommandType.Text


                        saveInto.CommandText = "UPDATE login SET password='" & TextBox3.Text & "' WHERE username ='" & TextBox1.Text & "'"


                        conn.Open()
                        saveInto.ExecuteNonQuery()
                        conn.Close()
                        MsgBox("Change Password Successful!!", MsgBoxStyle.Information, "Change Pass")

                    Catch ex As Exception
                        MsgBox(ex.Message)
                    End Try
                End If
            End If
        Catch ex As Exception
            MsgBox("Error")
        End Try

    End Sub

End ClassImports System.Data.OleDb



Friend Class login
    Public cn As New OleDbConnection
    Public cmd As New OleDbCommand
    Public da As OleDbDataAdapter
    Public dr As OleDbDataReader
    Public ds As DataSet = New DataSet
    Public qry As String = Nothing
    Public conString As String = ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=../data/Philam.mdb")

    Public Sub myCn()
        If cn.State = ConnectionState.Open Then cn.Close()
        cn.ConnectionString = conString
        cn.Open()
    End Sub


    Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox2.PasswordChar = "*"
        Me.CenterToScreen()
        Button3.Hide()
        Label3.Hide()
        TextBox3.Hide()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Or TextBox2.Text = "" Then Exit Sub


        Dim acc As New System.Text.StringBuilder
        acc.AppendLine("SELECT username and password")
        acc.AppendLine("FROM Login WHERE")
        acc.AppendLine("username=@name AND")
        acc.AppendLine("password=@word")

        Try
            Using cn As New OleDbConnection(conString)
                cn.Open()

                Dim cmd As New OleDbCommand(acc.ToString, cn)
                cmd.Parameters.AddWithValue("@name", TextBox1.Text)
                cmd.Parameters.AddWithValue("@word", TextBox2.Text)
                dr = cmd.ExecuteReader
                If dr.HasRows Then

                    Me.Hide()
                    mainForm.Show()
                    TextBox1.Text = ""
                    TextBox2.Text = ""



                Else
                    MsgBox("Invalid username or password", MsgBoxStyle.Exclamation)
                End If
                dr.Close()
            End Using
        Catch ex As Exception
            MessageBox.Show("ERROR" & ex.Message.ToString, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()

    End Sub



    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Button1.Hide()
        Button3.Show()
        Label3.Show()
        TextBox3.Show()

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If TextBox1.Text = Nothing Then
            MsgBox("Please enter your username", MsgBoxStyle.Critical)
            TextBox1.Focus()
        End If

        If TextBox2.Text = Nothing Then
            MsgBox("Please enter your old password", MsgBoxStyle.Critical)
            TextBox2.Focus()
        End If

        If TextBox3.Text = Nothing Then
            MsgBox("Please enter a new password", MsgBoxStyle.Critical)
            TextBox3.Focus()
        End If

        Dim n As String
        Try
            n = (Me.TextBox2.Text)

            Dim accQuery As String = "SELECT * FROM login WHERE username= '" & TextBox1.Text & "' and password='" & n & "'"

            Dim dataset1 As New DataSet
            Dim dataadapter As New OleDbDataAdapter(accQuery, conString)
            dataadapter.Fill(dataset1, "login")

            If Me.BindingContext(dataset1, "login").Count = 0 Then
                MsgBox("The old password is Incorrect", MsgBoxStyle.Critical, "Error")
            Else
                If Me.BindingContext(dataset1, "login").Count > 0 Then
                    Try
                        Dim saveInto As New OleDb.OleDbCommand
                        Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=../data/Philam.mdb"
                        Dim conn As New OleDbConnection(conStr)
                        saveInto.Connection = conn
                        saveInto.CommandType = CommandType.Text
                        **saveInto.CommandText = "UPDATE login SET password='" & TextBox3.Text & "' WHERE username ='" & TextBox1.Text & "'"**
                        conn.Open()
                        saveInto.ExecuteNonQuery()
                        conn.Close()
                        MsgBox("Change Password Successful!!", MsgBoxStyle.Information, "Change Pass")

                    Catch ex As Exception
                        MsgBox(ex.Message)
                    End Try
                End If
            End If
        Catch ex As Exception
            MsgBox("Error")
        End Try

    End Sub

End Class

tnx and TIA =)

Are you receiving any errors, or is the database just not getting updated?

tnx for the reply i solved it by the way =) ., i received an error message regarding my UPDATE statement it seem that im just missing the brackets .., instead of "password" it was supposed to be "[password]" tnx any way =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.