Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - 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 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
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 - Wasteful Creation of ADO Objects


    (Page 4 of 5 )

    As mentioned earlier, every ADO object has a definite scope and purpose. These objects should be created sparingly -- only when they are required. Creating ADO objects indiscriminately puts a lot of load on the system resources.

    Connection object is indispensable. It has to be created. But you can certainly do away with the need of other two objects depending upon the requirement of the program. For instance, when you need an editable Recordset, all you need is Connection and Recordset objects. In the example that we discussed above, there was in fact no need to create the Recordset object. We discussed it just to pinpoint how sometimes you might end up creating a Recordset that is read-only and forward-only despite having declared proper cursor and lock types. For the purpose of creating an editable recordset, the following code could have fit the same bill, but with more efficiency: 

    Private Sub Form_Load()
    Set Con = New ADODB.Connection
    Set Rst = New ADODB.Recordset
    With Con
    .Provider = "SQLOLEDB"
    .ConnectionString = "user id= sa; password=; initial catalog=videolib"
    .Open
    End With
    Rst.Open “Select * from Actors”, Con, adOpenDynamic, adLockOptimistic
    End with
    End Sub

    Similarly, when you just need to fetch records in a recordset, and the recordset doesn’t have to be editable, all you need to do is to create a Connection object, and use its Execute method to run an SQL statement. Here it goes:

    Private Sub Form_Load()
    Set Con = New ADODB.Connection
    With Con
    .Provider = "SQLOLEDB"
    .ConnectionString = "user id= sa; password=; initial catalog=videolib"
    .Open
    End With
    Set Rst  = Con.Execute (Select * from Actors)
    End Sub

    In the above example, we saved the system resources by eliminating the need of Command and Recordset objects. This will in turn make the program more efficient. Efficiency is the buzzword in the real world of programming. How a programmer uses system resources reflects his or her efficiency as a programmer, since execution of code is not the issue in the real world of programming. What matters most is the efficiency.

    More Visual Basic.NET Articles
    More By Maneesh Makheeja


     

    VISUAL BASIC.NET ARTICLES

    - 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...
    - Shadowing using Shadows in Visual Basic.NET ...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway