Passing Updated Recordset Objects to the Middle Tier

You can pass updated Recordset objects from client computers to the middle tier and the database server by using:

Using RDSIE3.DataControl to Pass Updated Disconnected Recordset Objects Back to the Middle Tier

Data-bound controls enable the user to visually edit, add, or delete records. All changes by the user are stored locally until the user explicitly submits or cancels the update.

Typically, you will bind a grid control to an RDSIE3.DataControl object, and then add, edit, and delete records in the client-side Recordset via the user interface. After you update the client-side data, you need to save the changed information to the database by using the SubmitChanges method with the RDSIE3.DataControl object. The SubmitChanges method submits pending changes of the locally cached updatable Recordset to the OLE DB data source specified in the RDSIE3.DataControl object's Connect property.

The following code example shows how to do this:

Sub Update_OnClick
	ADC1.SubmitChanges
End Sub

Only the changed records are sent for modification, and either all of the changes succeed or all of them fail together.

You can also include a Cancel button to cancel changes to the Recordset:

Sub Cancel_OnClick
	ADC1.CancelUpdate
End Sub

Notes

Multiuser Issues and Record Locking

Because users are working with disconnected Recordset objects on a client-side cache, there may be multiuser issues. For instance, when two different users try to update the same record, Remote Data Service simply allows the user who updates the record first to "win." The second user's update request will fail with an error.

Using ADO to Pass Recordset Objects to the Middle Tier

You can use the ADOR.Recordset object to marshal recordsets from a client Web page to a middle-tier business object. For example, suppose a user connects to a virtual shopping mall and selects a number of items to purchase. The selected items appear in the virtual shopping cart that is implemented with the RDSIE3.DataControl object and buffered in a rowset. When the client clicks the purchase button, an ADOR.Recordset object is created and passed to an application server as an input parameter to a business function (ApplyUpdates). This causes the Recordset to be marshaled across to the server. The ApplyUpdates business function then connects to the Sales database and applies the updates.

' Code on a client Web page.
Sub PurchaseItem_OnClick
	Set rst = ADC1.Recordset

	' The following option tells the recordset to send 
	' back changed records only when working with
	' updates. 
	' This makes the roundtrips more lightweight. 
	' The value of 1 is the same as setting it to 
	' adMarshalModifiedOnly.
	rst.MarshalOptions = 1

	' Call the ApplyUpdates function on the MyObj
	' business object and pass the ADOR.Recordset
	' object as an input parameter.
	MyObj.ApplyUpdates rst

End Sub


' VB code in the business object.
' ApplyUpdates is a method in a 
' middle-tier business object. 
Sub ApplyUpdates(rst As ADOR.Recordset)

	Dim rs As New ADODB.Recordset

	rs.ActiveConnection =  _
		"DSN=SalesDB;UID=SMgr;PWD=password

	rs.Open rso

	' Call a method on the ADODB.Recordset to save
	' updates.
	rs.UpdateBatch

End Sub 

Database Updatability Features

Updatability is defined as being able to insert and delete records, and update the contents of one or more records.

With Remote Data Service 1.1, you can update a number of databases, including Microsoft® SQL Server, Microsoft Access, Oracle, and so forth. This is different from previous versions, which supported built-in updatability only with SQL Server databases.

The table being updated must contain a key or index column to specify record uniqueness.

In general, avoid retrieving updatable Recordset objects that can contain duplicate records, because this can lead to data corruption. A status return code of DB_S_ERRORSOCCURED will occur if the WHERE clause identifies duplicate records. If this happens, then more columns should be added to the query so that uniqueness can be achieved. Computed fields, Long Binary fields, and Text fields aren't used in record identification for updating, so at least one column of another type should be included in the query.