Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is it good idea to bind recordset to control?
Message
 
To
21/11/2000 16:57:35
Christian Bellavance
Université du Québec à Hull
Hull, Quebec, Canada
General information
Forum:
Visual Basic
Category:
Database DAO/RDO/ODBC/ADO
Miscellaneous
Thread ID:
00444047
Message ID:
00444442
Views:
8
>How your SQL Update query will know that the data has changed?
>
>I will say that in french, il will be more specific (sorry for my english)
>
>La question que je me pose est:
>
>Si j'obtiens des données via un SELECT et que je les affichent sur un formulaire. Lorsque je vais les enregistrer (SQL UPDATE), comment puis-je savoir si un autre utilisateur n'aurra pas fait un SELECT après moi et aura fais son SQL UPDATE avant moi sur le même enregistrement? Parce que dans ce cas là, mon SQL UPDATE ne devrait pas avoir lieu pour ne pas effacer ce que l'autre utilisateur a fait.
>
>Si ce n'est pas encore claire, dis le moi.
>
>Merci

The thing I haven't said yet is that I always have a timestamp field in my tables.

Look at this code:
Option Explicit

Private mcn As ADODB.Connection
Private mrs As ADODB.Recordset

Private Sub cmdNext_Click()
    With mrs
        .MoveNext
        If .EOF Then .MoveLast
    End With
    Call FillFields
End Sub

Private Sub cmdPrevious_Click()
    With mrs
        .MovePrevious
        If .BOF Then .MoveFirst
    End With
    Call FillFields
End Sub

Private Sub cmdUpdate_Click()
Dim intRecord As Integer

    mcn.Execute "Update Authors " & _
                "Set Author = '" & Replace(Text2.Text, "'", "''") & "' " & _
                ", LastModif = '" & Now & _
                "' where au_id = " & Text1.Text & _
                " And LastModif = #" & Label1.Caption & "#", intRecord
    If intRecord = 0 Then MsgBox "The record have been modified since it was read!!!"
    Call OpenRS
End Sub

Private Sub Form_Load()
    Set mcn = New ADODB.Connection
    With mcn
        .CursorLocation = adUseClient
        .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\BIBLIO2000.MDB;Persist Security Info=False"
        .Open
    End With
    Call OpenRS
End Sub

Private Sub FillFields()
    Text1.Text = mrs!Au_id
    Text2.Text = mrs!Author
    Label1.Caption = mrs!LastModif & ""
End Sub

Private Sub OpenRS()
    Set mrs = New ADODB.Recordset
    mrs.Open "select * from authors", mcn, adOpenStatic, adLockReadOnly
    Call FillFields
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform