Click here to Skip to main content
15,887,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I doing employee data maintenance project. In this change password section make arise update command syntax error. I attach my coding. someone help me.
thank U........
VB
If TextBox3.Text.Length < 4 And TextBox3.Text.Length > 12 Then
            MsgBox("PASSWORD SHOULD ATLEAST 4 CHARACTER AND NOT MORE THAN 12")
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
        ElseIf TextBox2.Text = TextBox3.Text Then
            MsgBox("NEW PASSWORD IS SAME AS OLD PASSWORD")
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
        ElseIf (TextBox3.Text = TextBox4.Text) Then
            Try
                con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\SampleDB1.mdb")
                con.Open()
                Dim ds As New DataSet
da = New OleDbDataAdapter("select * from empdetails1 where empname = '" & Trim(TextBox1.Text) & "' and password = ' " & Trim(TextBox2.Text) & "'", con)
                If da.Fill(ds) Then
                    cmd = New OleDbCommand("update empdetails1 set password = '" + TextBox3.Text + "' where empname = '" + TextBox1.Text + "'", con)
                    cmd.ExecuteNonQuery()
                    MessageBox.Show("PASSWORD CHANGE SUCCESSFULLY")
                    con.Close()
                    Me.Hide()
                    Form1.Show()
                Else
                    MsgBox("INVALID PASSWORD OR USERNAME")
                    TextBox1.Text = ""
                    TextBox2.Text = ""
                    TextBox3.Text = ""
                    TextBox4.Text = ""
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            MsgBox("NEW AND RETRY PASSWORD IS NOT MATCH")
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
        End If
Posted

VB
If TextBox3.Text.Length < 4 And TextBox3.Text.Length > 12 Then
            MsgBox("PASSWORD SHOULD ATLEAST 4 CHARACTER AND NOT MORE THAN 12")
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
        ElseIf TextBox2.Text = TextBox3.Text Then
            MsgBox("NEW PASSWORD IS SAME AS OLD PASSWORD")
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
        ElseIf (TextBox3.Text = TextBox4.Text) Then
            Try
                con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\SampleDB1.mdb")
                con.Open()
                cmd = New OleDbCommand("update empdetails1 set [password] = '" + TextBox3.Text + "' where empname = '" + TextBox1.Text + "'", con)
                cmd.ExecuteNonQuery()
                MessageBox.Show("PASSWORD CHANGE SUCCESSFULLY")
                con.Close()
                Me.Hide()
                Form1.Show()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            MsgBox("NEW AND RETRY PASSWORD IS NOT MATCH")
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
        End If
 
Share this answer
 
Comments
[no name] 13-Dec-11 0:21am    
5! This should do it.
Member 12874995 29-Jul-17 23:39pm    
this works perfect but if u give wrong old password and enter it is showing password change successfully,pls c that if old password is not correct it should show wrong password.pls maek it sure
Repalce the + with & in UPDATE QUERY....

VB
cmd = New OleDbCommand("update empdetails1 set password = '" & TextBox3.Text & "' where empname = '" & TextBox1.Text & "'", con)
 
Share this answer
 
v2
Comments
ckulasekaran 12-Dec-11 1:52am    
using & in update query also arise same error
NikulDarji 12-Dec-11 2:25am    
I think there is no need of SELECT statement u can directly fire the UPDATE query after opening the connection...because u r selecting the new password direct form Textbox...
Suggestion please
Change the following
VB
  'TextBox1.Text = ""
  'TextBox2.Text = ""
  'TextBox3.Text = ""
  'TextBox4.Text = ""
  'Form1.show
  'If TextBox3.Text.Length < 4 And TextBox3.Text.Length > 12 Then
 
'YOUR TRY CATCH MESSAGE'
'Catch ex As Exception
'    MsgBox(ex.Message)
'End Try

To 

   'TextBox1.Text = String.Empty
   'TextBox2.Text = String.Empty
   'TextBox3.Text = String.Empty
   'TextBox4.Text = String.Empty
   'Form1.Showdialog()
   'If TextBox3.Text.Length < 4 OR TextBox3.Text.Length > 12 Then
 
'YOUR TRY CATCH MESSAGE'

Catch ex As Exception
   MessageBox.Show("Error while Chnging Password " & ex.Message & vbCrLf &  "Please contact ITC", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try

And please Check Your Naming Convention
For ex: txtPassword.Text etc . . .
 
Share this answer
 
v2
Comments
[no name] 13-Dec-11 0:22am    
EDIT: always wrap your codes with "pre" tag to separate codes from text.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900