Sun
ONE Active Server Pages Product Home Page Developer Site Version
 

ContentsPreviousNextIndex



ADO Field Object OriginalValue Property

The value of a Field object that existed in the record before any changes were made. This property is not currently supported on UNIX.

OriginalValue Property Return Values (ADO Field Object)

Returns a Variant value.

OriginalValue Property Remarks (ADO Field Object)

Use the OriginalValue property to return the original field value for a field from the current record.

In immediate update mode (the provider writes changes to the underlying data source once you call the ADO Recordset Object Update Method), the OriginalValue property returns the field value that existed prior to any changes (that is, since the last Update method call). This is the same value that the ADO Recordset Object CancelUpdate Method uses to replace the ADO Field Object Value Property.

In batch update mode (the provider caches multiple changes and writes them to the underlying data source only when you call the ADO Recordset Object UpdateBatch Method), the OriginalValue property returns the field value that existed prior to any changes (that is, since the last UpdateBatch method call). This is the same value that the ADO Recordset Object CancelBatch Method uses to replace the Value property. When you use this property with the UnderlyingValue property, you can resolve conflicts that arise from batch updates. Batch updates are currently not supported on UNIX.

OriginalValue Property Example (ADO Field Object)

This Visual Basic example demonstrates the OriginalValue and UnderlyingValue properties by displaying a message if a record's underlying data has changed during a ADO Recordset Object batch update.

Public Sub OriginalValueX()
Dim cnn1 As ADODB.Connection 
Dim rstTitles As ADODB.Recordset 
Dim fldType As ADODB.Field 
Dim strCnn As String
' Open connection.
Set cnn1 = New ADODB.Connection 
strCnn = "driver={SQL Server};server=srv;" & _ 
"uid=sa;pwd=;database=pubs"
cnn1.Open strCnn
' Open recordset for batch update.
Set rstTitles = New ADODB.Recordset 
Set rstTitles.ActiveConnection = cnn1 
rstTitles.CursorType = adOpenKeyset 
rstTitles.LockType = adLockBatchOptimistic 
rstTitles.Open "titles"
' Set field object variable for Type field.
Set fldType = rstTitles!Type
' Change the type of psychology titles.
Do Until rstTitles.EOF 
If Trim(fldType) = "psychology" Then 
fldType = "self_help" 
End If 
rstTitles.MoveNext 
Loop
' Similate a change by another user by updating 
' data using a command string. 
cnn1.Execute "UPDATE titles SET type = 'sociology' " & _ 
"WHERE type = 'psychology'"
'Check for changes. 
rstTitles.MoveFirst 
Do Until rstTitles.EOF
If fldType.OriginalValue <> _ 
fldType.UnderlyingValue Then 
MsgBox "Data has changed!" & vbCr & vbCr & _ 
" Title ID: " & rstTitles!title_id & vbCr & _ 
" Current value: " & fldType & vbCr & _ 
" Original value: " & _ 
fldType.OriginalValue & vbCr & _ 
" Underlying value: " & _ 
fldType.UnderlyingValue & vbCr
End If 
rstTitles.MoveNext 
Loop 
' Cancel the update because this is a demonstration.
rstTitles.CancelBatch 
rstTitles.Close
' Restore original values.
cnn1.Execute "UPDATE titles SET type = 'psychology' " & _
"WHERE type = 'sociology'"
cnn1.Close
End Sub


ContentsPreviousNextIndex