adding and deleting rdoresultset rows

3
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. Use these steps to add a specific row in an rdoResultset: 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). Use these steps to delete a specific row in an rdoResultset: 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. Making Changes with RDO Action Queries A more efficient alternative to using the Edit, AddNew, Delete, and Update methods is to use the Execute method. By executing an SQL query that contains one or more UPDATE, INSERT, or DELETE statements, you can make changes to the database without using the RDO methods. Depending on the type of data source and its ability to support complex multistatement operations, these SQL statements can contain logic that performs so-called "make-table" or SELECT INTO queries that create new permanent or

Upload: lalitha

Post on 07-Apr-2015

33 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 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.

Use these steps to add a specific row in an rdoResultset:

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).

Use these steps to delete a specific row in an rdoResultset:

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.

Making Changes with RDO Action Queries A more efficient alternative to using the Edit, AddNew, Delete, and Update methods is to use the Execute method. By executing an SQL query that contains one or more UPDATE, INSERT, or DELETE statements, you can make changes to the database without using the RDO methods. Depending on the type of data source and its ability to support complex multistatement operations, these SQL statements can contain logic that performs so-called "make-table" or SELECT INTO queries that create new permanent or

Page 2: Adding and Deleting RdoResultset Rows

temporary tables or perform other complex operations. You must manage the errors and concurrency yourself. You can also submit transaction statements that bind the operations into one or more atomic sets using the SQL syntax supported by your data source. Because the Execute method also supports the rdAsyncEnable option, these operations can be performed asynchronously.

Option Explicit Dim er As rdoError Dim cn As New rdoConnection Dim qy As New rdoQuery Dim rs As rdoResultset Dim col As rdoColumn Private Sub AddNewJob_Click() On Error GoTo ANEH 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

Page 3: Adding and Deleting RdoResultset Rows

End Sub Private Sub Form_Load() 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