Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 5 - 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 - The Purpose of Command Objects


    (Page 5 of 5 )

     

    Now the only question that remains unanswered is, What the heck is Command object used for? The answer is -- in two cases.

    1. When we have to execute a stored procedure created at the backend. We need to use the CommandType property of the Command object to specify that the SQL statement is a stored procedure, and the CreateParameter method to create a parameter that is assigned to the Parameter object. Finally, the Execute method executes the stored procedure.
    2. When we need to access more than one table through a single Visual Basic form and store them in a forward-only, unalterable recordset. This is accomplished by creating as many Command objects as the tables to be accessed. Every Command object in this case is made to represent the respective table by binding the CommandText property of the Command object with the respective table in the SQL statement:

    .CommandText = “Select * from Actors”

    Here’s the complete code for accessing two tables -- Actors and Directors, using two command objects with a single Connection object:

    Private Sub Form_Load()
    Set Con = New ADODB.Connection
    Set Com = New ADODB.Command
    Set Com1 = New ADODB.Command
    With Con
    .Provider = "SQLOLEDB"
    .ConnectionString = "user id= sa; password=; initial catalog=videolib"
    .Open
    End With
    With Com
    .ActiveConnection = Con
    .CommandText = “Select * from Actors”
    .Execute
    End With
    With Com1
    .ActiveConnection = Con
    .CommandText = “Select * from Directors”
    .Execute
    End with
    End Sub

    NOTE  Apart from creating multiple Command objects for accessing multiple tables, we can also accomplish the same by creating a single Recordset object, which can be bound to multiple tables using a different SQL statement for each table. This eliminates the need of creating Command object, thus enhancing the performance of the program. Here’s the sample code for the same:

    Rst.Open “Select * from Actors”, &  _
    “Select * from Directors”, Con, adOpenDynamic, adLockOptimistic
    Do While Not <some conditions>
    Loop
    Set Rst = Rst.NextRecordset
    Do While Not <some conditions>
    Loop

    The NextRecordset method of Recordset object here will take you to the next recordset.

    Conclusion

    We just saw how the prospect of an efficient and error-free Visual Basic application boils down to one’s familiarity with the ADO concepts. So, before you go on to code that first Visual Basic application, it makes sense to first get your feet in the ADO concepts. For, programming in Visual Basic is more about knowing the ins and outs ADO rather than Visual Basic itself.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    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 1 hosted by Hostway
    Stay green...Green IT