Previous | Index | Next 

[PRB] Disappearing records in client-side ADODB.Recordset with batch optimistic lock

Consider the following VB6 code:

        Dim rs As New ADODB.Recordset()
        rs.Fields.Append("field1", ADODB.DataTypeEnum.adVarChar, 2, _
              ADODB.FieldAttributeEnum.adFldIsNullable)
        rs.Fields.Append("field2", ADODB.DataTypeEnum.adVarChar, 2, _
              ADODB.FieldAttributeEnum.adFldIsNullable)
  
        rs.Open(, , ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic)
        rs.AddNew(Array6("field1", "field2"), Array6("a1", "b1"))
        rs.AddNew(Array6("field1", "field2"), Array6("a2", "b2"))
        rs.AddNew(Array6("field1", "field2"), Array6("a3", "b3"))
  
        DataGrid1.DataSource = rs

After the migration to VB.NET the above code runs fine, except that whenever you click on a row in the DataGrid control, a record is deleted.

The workaround is quite simple, though: you just need to confirm the insertion of the new rows by means of an UpdateBatch method, before the recordset is assigned to the DataGrid.DataSource property. The easiest way to do so is by means of an InsertStatement pragma:

        '## InsertStatement rs.UpdateBatch()
        DataGrid1.DataSource = rs

 

Previous | Index | Next