Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - Visual Basic Programming: Much Ado about A...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Visual Basic Programming: Much Ado about ADO
By: Maneesh Makheeja
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 40
    2004-06-15

    Table of Contents:
  • Visual Basic Programming: Much Ado about ADO
  • Not Specifying the Library Being Referred To
  • Improper Ways of Opening the Recordset Object
  • Wasteful Creation of ADO Objects
  • The Purpose of Command Objects

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Visual Basic Programming: Much Ado about ADO - Improper Ways of Opening the Recordset Object


    (Page 3 of 5 )

    One reason why ADO programming is a tricky business is mainly because ADO objects offer more than one method of executing an SQL statement, and the novices are often given to the belief that any way they do it is going to be fine. Well, here’s the catch. Have a look at the following piece of code:

    Private Sub Form_Load()
    Set Con = New ADODB.Connection
    Set Com = New ADODB.Command
    Set Rst = New ADODB.Recordset
    With Con
    .Provider = "SQLOLEDB"
    .ConnectionString = "user id= sa; password=; initial catalog=videolib"
    .Open
    End With
    Com.ActiveConnection = Con
    Set Rst= Com.Execute (Select * from Actors)
    With Rst
    .CursorLocation = adUseServer
    .CursorType = adOpenDynamic
    .LockType = adLockOptimistic
    End with
    End Sub

    This code will work fine as far as establishing connection and fetching and displaying data in the Visual Basic form is concerned. The big shock comes when you try the MovePrevious, Delete and AddNew methods of the Recordset objects. An error pops up saying, “The operation requested by you is not supported by the provider”.

    Don’t go by what the error reads. There’s nothing wrong with the provider. The problem lies in how the Recordset object has been created in this example. Actually, when you use Execute method of Connection or the Command object, the Recordset created is by default a read-only and forward-only. That’s why, despite having specified the appropriate cursor type and lock type, the Recordset won’t allow you to navigate backwards or modify the records.

    To create a Recordset that allows addition and deletion of records and navigation in both directions, the Open method of the Recordset object must be used with the appropriate cursor type and lock type. Here’s how:

    Rst.Open “Select * from Actors”, Con, adOpenDynamic, adLockOptimistic

    More Visual Basic.NET Articles
    More By Maneesh Makheeja


     

    VISUAL BASIC.NET ARTICLES

    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET (F...
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT