Dim rs1 As New Recordset
Dim rs2 As New Recordset
Dim cn As New Connection
cn.CursorLocation = adUseClient
cn.Open "Provider=SQLOLEDB;Data Source=MyServer;Initial Catalog=Pubs;User ID=sa;Password=;"
On Error Resume Next
cn.Execute "Drop Table T1"
cn.Execute "CREATE TABLE T1 (K1 Int PRIMARY KEY, F2 Int)"
On Error GoTo 0
cn.Execute "INSERT INTO T1 VALUES(0, 100)"
rs1.Open "Select K1, F2 From T1", cn, adOpenForwardOnly, adLockReadOnly
'Commenting the above line and uncommenting the next line will not generate the error.
'rs1.Open "Select K1, F2 From T1", cn, adOpenKeyset, adLockOptimistic
If Dir("Persist.xml") <> "" Then Kill "Persist.xml"
rs1.Save "Persist.xml", adPersistXML
rs2.Open "Persist.xml", cn, adOpenKeyset, adLockBatchOptimistic, adCmdFile
rs2.AddNew
rs2("K1") = 1
rs2("F2") = "200"
rs2.UpdateBatch 'Error occurs here