Microsoft ActiveX Data ObjectsMicrosoft ActiveX Data Objects*
*Contents  *Index  *Topic Contents

CursorType, LockType, and EditMode Properties Example

This example demonstrates setting the CursorType and LockType properties before opening a Recordset. It also shows the value of the EditMode property under various conditions. The EditModeOutput function is required for this procedure to run.

Public Sub EditModeX()

	Dim cnn1 As ADODB.Connection
	Dim rstEmployees As ADODB.Recordset
	Dim strCnn As String

	' Open recordset with data from Employee table.
	Set cnn1 = New ADODB.Connection
	strCnn = "driver={SQL Server};server=srv;" & _
		"uid=sa;pwd=;database=pubs"
	cnn1.Open strCnn
		
	Set rstEmployees = New ADODB.Recordset
	Set rstEmployees.ActiveConnection = cnn1
	rstEmployees.CursorType = adOpenKeyset
	rstEmployees.LockType = adLockBatchOptimistic
	rstEmployees.Open "employee", , , , adCmdTable

	' Show the EditMode property under different editing
	' states.
	rstEmployees.AddNew
	rstEmployees!emp_id = "T-T55555M"
	rstEmployees!fname = "temp_fname"
	rstEmployees!lname = "temp_lname"
	EditModeOutput "After AddNew:", rstEmployees.EditMode
	rstEmployees.UpdateBatch
	EditModeOutput "After UpdateBatch:", rstEmployees.EditMode
	rstEmployees!fname = "test"
	EditModeOutput "After Edit:", rstEmployees.EditMode
	rstEmployees.Close
	
	' Delete new record because this is a demonstration.
	cnn1.Execute "DELETE FROM employee WHERE emp_id = 'T-T55555M'"

End Sub

Public Function EditModeOutput(strTemp As String, _
	intEditMode As Integer)

	' Print report based on the value of the EditMode 
	' property.
	Debug.Print strTemp
	Debug.Print "    EditMode = ";

	Select Case intEditMode
		Case adEditNone
			Debug.Print "adEditNone"
		Case adEditInProgress
			Debug.Print "adEditInProgress"
		Case adEditAdd
			Debug.Print "adEditAdd"
	End Select

End Function

Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.