Click here to Skip to main content
15,889,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I have developing project in Visual Studio-2015 using Access database as back end. While running below code I do not encounter any Error Message and does not update record in table:

Please Help

What I have tried:

Private Sub BtnUpdate_Click(sender As Object, e As EventArgs) Handles BtnUpdate.Click
      BtnUpdate.Enabled = False : Dbconnection.Close() : Dbconnection.Open()

      EdtEmpCmd.CommandText = "UPDATE EMP_MASTER  ) " &
      "( SET Sap_No= @Sap_No, CPF_No= @CPF_No, Name = @Name, Designation= @Designation, DesigIndex= @DesigIndex, CompJoining= @CompJoining)" &
       "( TPSJoining=@TPSJoining, QtrNo=  @QtrNo, DOB= @DOB, DOR= @DOR, BloodGroup=  @BloodGroup,  MobileNo=  @MobileNo, CLAvail=  @CLAvail) " &
      "(FLAvail=@FLAvail, CLBal= @CLBal, FLBal=@FLBal, EmailID=  @EmailID, Status=@Status where Sap_No= @Sap_No) ;   "

      EdtEmpCmd.CommandType = CommandType.Text
      Try

          EdtEmpCmd.Parameters.AddWithValue("@Sap_No", CInt(TxtSapID.Text))

          EdtEmpCmd.Parameters.AddWithValue("@CPF_No", TxtCPFNo.Text.ToString())

          EdtEmpCmd.Parameters.AddWithValue("@Name", TxtEmpName.Text.ToString())

          EdtEmpCmd.Parameters.AddWithValue("@Designation", CmbDesignation.Text.ToString())

          EdtEmpCmd.Parameters.AddWithValue(" @DesigIndex", CmbDesignation.SelectedIndex + 1)

          EdtEmpCmd.Parameters.AddWithValue(" @CompJoining", DtpCompJoining.Value.ToShortDateString)

          EdtEmpCmd.Parameters.AddWithValue(" @TPSJoining", DtpTPSJoining.Value.ToShortDateString)

          EdtEmpCmd.Parameters.AddWithValue("@QtrNo", TxtQtrNo.Text.ToString())

          EdtEmpCmd.Parameters.AddWithValue("@DOB", DtpBirthDate.Value.ToShortDateString)

          EdtEmpCmd.Parameters.AddWithValue("@DOR", DtpRetirementDate.Value.ToShortDateString)

          EdtEmpCmd.Parameters.AddWithValue("@BloodGroup", CmbBloodGroup.Text.ToString())

          EdtEmpCmd.Parameters.AddWithValue("@MobileNo", TxtMobileNo.Text.ToString())

          EdtEmpCmd.Parameters.AddWithValue("@CLAvail", CInt(TxtClAvail.Text))

          EdtEmpCmd.Parameters.AddWithValue("@FLAvail", CInt(TxtFlAvail.Text))

          EdtEmpCmd.Parameters.AddWithValue("@CLBal", (CInt(15 - TxtClAvail.Text)))

          EdtEmpCmd.Parameters.AddWithValue("@FLBal", (CInt(6 - TxtFlAvail.Text)))

          EdtEmpCmd.Parameters.AddWithValue("@EmailID", TxtEmailID.Text.ToString())

          EdtEmpCmd.Parameters.AddWithValue("@Status", "A")

          AddEmpCmd.ExecuteNonQuery()
          Call ScrnClr()
          Dbconnection.Close()
          'Exit Sub
      Catch ex As Exception
          MessageBox.Show(ex.Message)

      End Try

  End Sub
Posted
Updated 8-Jul-18 23:08pm

Firstly - you have a syntax errors in your SQL...
SQL
"UPDATE EMP_MASTER  ) "
Try removing all of those extraneous brackets and putting in some extra commas
SQL
UPDATE EMP_MASTER  
 SET Sap_No= @Sap_No, CPF_No= @CPF_No, Name = @Name, Designation= @Designation, DesigIndex= @DesigIndex, CompJoining= @CompJoining,
 TPSJoining=@TPSJoining, QtrNo=  @QtrNo, DOB= @DOB, DOR= @DOR, BloodGroup=  @BloodGroup,  MobileNo=  @MobileNo, CLAvail=  @CLAvail, 
FLAvail=@FLAvail, CLBal= @CLBal, FLBal=@FLBal, EmailID=  @EmailID, Status=@Status where Sap_No= @Sap_No ;  

Next question is obviously, is there actually a record with sap_no with a value that's in the txtSapId textbox? One to watch out for as you are assuming that an integer has been enetered into that text box

On another note, all those Txt....Text.ToString() ... the .ToString() is unecessary, you are literally saying "convert this string to a string"
 
Share this answer
 
Then use the debugger: put a breakpoint on the line
EdtEmpCmd.Parameters.AddWithValue("@Sap_No", CInt(TxtSapID.Text))
And find out exactly what is in TxtSapID.Text and what CInt returns as a value from it.
Then manually use Access to open the file - before you step any further into the update - and SELECT all rows with that value in Sap_no
Look at them - are there any? Your WHERE clause requires an exact match.
Step the debugger through the code and make a note of the values you are updating to. Compare them to the values currently in the DB.
When you get to the line
AddEmpCmd.ExecuteNonQuery()
execute it, and rerun the SELECT command to check what happened. Did the values change as expected?

We can't do any of that for you: we don't have any access to your machine or DB!
 
Share this answer
 

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