Editando dados de um Recordset com ADO ?

Quando você queria editar um registro usando a DAO seguia os seguintes passos:

  1. Abria o Recordset

  2. Executava o método EDIT

  3. Executava o método UPDATE 

 Dim db As DAO.Database

 Dim rst As DAO.Recordset

 

 Set db = DAO.DBEngine.OpenDatabase(CaminhoBD,False, False)

 Set rst = db.OpenRecordset("Clientes")

 

 rst.Edit

 rst!Nome = "Macoratti"

 rst.Update

End Sub

 

 

In ADO, however, all the rules have changed (see FIGURE 6). First, ADO will open a read-only recordset by default, so remember to set the lock type and cursor types in ADO to be updateable. And because there's no Edit method in ADO, you can begin editing your data. Lastly, you don't need to use the Update method; if you move to the next record, ADO will call the Update method for you behind the scenes. This can get you into trouble because DAO discarded any changes you made if you didn't execute the Update method. If you understand this, you understand the secret to editing data in ADO. Again, you won't want to edit SQL Server data this way. You should execute a Command object that calls a stored procedure that handles your edits.

 

Sub EditData_ADO()

   Dim conn As ADODB.Connection

  Dim rst As ADODB.Recordset

 

  Set conn = New ADODB.Connection

  With conn

     ' Set provider for Jet.

    .Provider = "Microsoft.Jet.OLEDB.4.0"

    .Mode = adModeReadWrite   ' Read/Write.

    .ConnectionString = "data source=" & DatabasePath$

    .Open

  End With

  Set rst = New ADODB.Recordset

  rst.Open "Employees", conn, _

           adOpenKeyset, adLockOptimistic

  ' Notice that there is no Edit method.

  rst!FirstName = "Stephen"

  ' Update method is unnecessary if you do a MoveNext.

  rst.Update

End Sub

E , é só ...