Results 1 to 14 of 14

Thread: [RESOLVED] Updated data is not showing using sql update query

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2012
    Posts
    40

    Resolved [RESOLVED] Updated data is not showing using sql update query

    Hi there
    I have made a login program where I used an Access Database and ADO for populating data. I have made a common module, named 'modCommon' where connecting string code exist like this:

    VBCode Code:
    1. Option Explicit
    2.  
    3. Public rsData As ADODB.Recordset
    4. Public conData As ADODB.Connection
    5.  
    6. 'Public DBConn As ADODB.Connection
    7. Public Function LoadDatabase() As ADODB.Connection
    8.     Set conData = New ADODB.Connection
    9.    
    10.     conData.Provider = "Microsoft.Jet.OLEDB.4.0"
    11.     conData.ConnectionString = "Data Source = " & App.Path & "\database.mdb"
    12.     conData.Properties("Jet OLEDB:Database Password") = "password"
    13.     conData.CursorLocation = adUseClient
    14.     conData.Open
    15.     Set LoadDatabase = conData
    16. End Function

    Now I have made a user maintenance form which is like below:


    When I try to update a record like adding a nick name to fullname like this:


    Record is being updated successfully:


    But If I press 'Next' Button and then 'Previous' the form is not showing updated data:


    But If I exit the form and reopen the form, then I can see the updated data.

    Name of the user maintenance form is form_admin in vb6 project.
    Code for form_load is as follows:
    VBCode Code:
    1. Private Sub Form_Load()
    2. Set rsData = LoadDatabase.Execute("Select * FROM users order by ID asc")
    3. DisplayRecord
    4. End Sub
    5.  
    6. Private Function DisplayRecord()
    7. Dim Ut As String
    8.  
    9. Ut = rsData.Fields("utype").Value
    10. txtFname.Text = rsData.Fields("fname").Value
    11. txtUser.Text = rsData.Fields("uname").Value
    12. txtPassword.Text = rsData.Fields("pword").Value
    13. cmboUType.Clear
    14. cmboUType.AddItem rsData("utype").Value
    15. cmboUType.ListIndex = 0
    16.  
    17.  
    18. If Ut <> "User" Then
    19. cmboUType.AddItem "User"
    20. End If
    21. If Ut <> "Admin" Then
    22. cmboUType.AddItem "Admin"
    23. End If
    24. If Ut <> "Banned" Then
    25. cmboUType.AddItem "Banned"
    26. End If
    27. If Ut <> "Restricted" Then
    28. cmboUType.AddItem "Restricted"
    29. End If
    30. If Ut <> "SuperAdmin" Then
    31. cmboUType.AddItem "SuperAdmin"
    32. End If
    33.  
    34. End Function

    And code for Update button is as follows:
    VBCode Code:
    1. Private Sub cmdUpdate_Click()
    2. Dim staffName As String
    3. Dim uid As Integer
    4.  
    5. 'rsBookmark = rsData.Bookmark
    6. staffName = rsData("uname").Value
    7. uid = rsData("ID").Value
    8. If MsgBox("If you click 'Yes', data will be updated." & vbCrLf & "Are you sure to update the data?", vbQuestion + vbYesNo, "Confirm Update") = vbYes Then
    9. LoadDatabase.Execute ("UPDATE users SET fname='" & txtFname.Text & "',uname='" & txtUser.Text & "',pword='" & txtPassword.Text & "',utype='" & cmboUType.List(cmboUType.ListIndex) & "' WHERE ID=" & uid & "")
    10. MsgBox "Record of " & staffName & " has been Updated", vbExclamation, "Record Updated"
    11. rsData.Requery
    12.  
    13. End If
    14. End If
    15. End Sub

    And the code for the 'Next' button is as follows:
    VBCode Code:
    1. Private Sub cmdNext_Click()
    2. rsData.MoveNext
    3. If rsData.EOF = True Then
    4. rsData.MoveLast
    5. MsgBox "No More User Exist!", vbInformation, "No User"
    6. Exit Sub
    7. Else
    8. DisplayRecord
    9. End If
    10. End Sub

    My question is why updated data is not showing after executing update sql query even after recordset.requery(rsData.Requery)? Where is the problem?

    Thanks in Advance
    Last edited by infomamun; May 6th, 2012 at 10:35 PM. Reason: Hiding original password and database name

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