Results 1 to 3 of 3

Thread: data not updated though everything wnet smooth

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908

    data not updated though everything wnet smooth

    Code:
    Private Sub cmdUpdate_Click()
    
    
    Dim objConn1 As New ADODB.Connection
    Set objCmd = New ADODB.Command
    objConn1.Open "DSN=PRsystem"
    
    Set objCmd.ActiveConnection = objConn1
    objCmd.CommandText = " UPDATE DataBase_T  SET Description =  ' " & txtD1.Text & " ' , Qty = ' " & txtQ1.Text & " ' , Unit_Cost = ' " & txtUC1.Text & " ' " & _
    " WHERE Description = ' " & describe & " '    And  Qty =  ' " & qty1 & " '  And  Unit_Cost = '  " & uc & " '  And PR_NO = ' " & Label15.Caption & " '    "
     objCmd.CommandType = adCmdText
     objCmd.Execute
     
     MsgBox " Data is updated."
    
    
    If Not objConn1 Is Nothing Then
        If objConn1.State Then
            objConn1.Close
      End If
        Set objConn1 = Nothing
    End If

    the above seems to have no error...cuz the msgbox would appear ...however i check the databse..and it was not updated!!!?why?

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    I would imagine you would get the msgbox if the data updated correctly, not incorrectly. Anyway, how about htis:

    objConn1.Execute (" UPDATE DataBase_T SET Description = ' " & txtD1.Text & " ' , Qty = ' " & txtQ1.Text & " ' , Unit_Cost = ' " & txtUC1.Text & " ' " & _
    " WHERE Description = ' " & describe & " ' And Qty = ' " & qty1 & " ' And Unit_Cost = ' " & uc & " ' And PR_NO = ' " & Label15.Caption & " ' ")

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    I would suspect your Where clause is incorrect. It does not find the record you are trying to update, which is not an error condition.

    Add this to your code
    VB Code:
    1. Private Sub cmdUpdate_Click()
    2. Dim objConn1 As New ADODB.Connection
    3. Dim lngRowsAffected as Long
    4.  
    5. Set objCmd = New ADODB.Command
    6. objConn1.Open "DSN=PRsystem"
    7.  
    8. Set objCmd.ActiveConnection = objConn1
    9. objCmd.CommandText = " UPDATE DataBase_T  SET Description =  ' " & txtD1.Text & " ' , Qty = ' " & txtQ1.Text & " ' , Unit_Cost = ' " & txtUC1.Text & " ' " & _
    10. " WHERE Description = ' " & describe & " '    And  Qty =  ' " & qty1 & " '  And  Unit_Cost = '  " & uc & " '  And PR_NO = ' " & Label15.Caption & " '    "
    11.  
    12. objCmd.CommandType = adCmdText
    13.  
    14. objCmd.Execute lngRowsAfffected
    15.  
    16. If lngRowsAffected > 0 Then
    17.   MsgBox "Updated " & lngRowsAffected & " Records."
    18. Else
    19.   MsgBox "Record does not exist with the specified criteria."
    20. End if
    21.  
    22. If Not objConn1 Is Nothing Then
    23.     If objConn1.State Then
    24.         objConn1.Close
    25.   End If
    26.     Set objConn1 = Nothing
    27. End If

    It looks like the problem with the Where clause is that you have to many spaces.

    Code:
    'this portion 
    Qty =  ' " & qty1 & " '  
    
    'should b
    Qty =  '" & qty1 & "'
    The other criterias have the same problem. Is the datatype of the QTY field Character or Numeric? If Numeric then remove the single quotes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width