Professional Documents
Culture Documents
Adding and Deleting RdoResultset Rows
Adding and Deleting RdoResultset Rows
In addition to changing columns in a specific row, you can add a row to an rdoResultset
which adds a row to a base table. This operations assumes that your application has read-
write access and permissions to add rows to the underlying table(s). Because this is often
not the case, be sure to investigate the WillUpdate event and the topics on using stored
procedures elsewhere in this chapter.
1. Use the AddNew method to create a temporary row buffer to hold the new row to
be added.
2. Provide a new value for each column you need to modify. To address the
temporary row buffer, simply address the rdoResultset object's columns as you
would when retrieving data from the columns.
3. Use the Update method to save the row to the data source.
After the row is added, the current row pointer is positioned on the row that was current
before the new row was added — if the cursor supports addressing new rows. If this is
the case, you can use the LastModified bookmark to move to the newly added row at the
end of the rdoResultset.
Once you’ve added rows, you can also delete them from the result set, assuming you also
have permission to delete data (you might not).
1. Position to the row using one of the Move methods or the AbsolutePosition or
PercentPosition property.
2. Use the Delete method to delete the row from the cursor (if any) and the data
source.
Once a row is deleted, the current row is no longer valid, so you must reposition to
another valid row in the rdoResultset.
Option Explicit
Dim er As rdoError
Dim cn As New rdoConnection
Dim qy As New rdoQuery
Dim rs As rdoResultset
Dim col As rdoColumn
With rs
.AddNew
!job_desc = JobDescription
!min_lvl = MinLevel
!max_lvl = MaxLevel
.Update
End With
Exit Sub
UpdateFailed:
MsgBox "Update did not suceed."
rs.CancelUpdate
Exit Sub
A
NEH:
Debug.Print Err, Error
For Each er In rdoErrors
Debug.Print er
Next
Resume UpdateFailed
End Sub
cn.CursorDriver = rdUseOdbc
cn.Connect = "uid=;pwd=;server=sequel;" _
& "driver={SQL Server};database=pubs;dsn=’’;"
cn.EstablishConnection
With qy
.Name = "JobsQuery"
.SQL = "Select * from Jobs"
.RowsetSize = 1
Set .ActiveConnection = cn
Set rs = .OpenResultset(rdOpenKeyset, _
rdConcurRowver)
Debug.Print rs.Updatable
End With
Exit Sub
End Sub