Decide Cursor Type and Lock Type based on CRUD Operation

Normally when we do the addition and deletion of record in the ADODB,cursor type and lock type will be changed.So we need to be very careful while adding and deleting a record using the record set object.So for this I have done a sample on addition only.
1. When we want to add using the record set object we need to pass the Cursor Type and Lock Type as
    ADODB.CursorTypeEnum.adOpenDynamic
   ADODB.LockTypeEnum.adLockOptimistic

2. By default, ADO record sets are opened with a lock type of adLockReadOnly, which does not allow additions and deletions.
3. To allow additions and deletions, open the record set with a lock type of either adLockOptimistic or adLockPessimistic
To Solve this we need change the code like this

Dim recordSetObj As New ADODB.RecordSet 
recordSetObj .Open("select * from students", "Your Connection Object", 
ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
 If Not recordSetObj .EOF Then 
recordSetObj .AddNew() 
End If
''Suppose If We want delete a record then we need to Give the 
''LockType as ADODB.LockTypeEnum.adLockPessimistic

Popular posts from this blog

Exporting to excel from a custom class object using C#.NET

Get the Clicked Cell Value and Column Name of GridView in ASP.NET

How to apply watermark to the textbox and dropdownlist?