Database
  Home arrow Database arrow Page 6 - ADO and the Command Object
Iron Speed
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 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
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? 
DATABASE

ADO and the Command Object
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 7
    2006-10-25

    Table of Contents:
  • ADO and the Command Object
  • Command Object in the Object Browser
  • Examples using the CommandType property
  • CommandType is adCmdStoredProc
  • CommandType is adCmdTable
  • CommandType is adCmdUnknown

  • 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
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    ADO and the Command Object - CommandType is adCmdUnknown
    (Page 6 of 6 )

    On SQL 2005 Server

    There is no equivalent in SQL 2005 Server. What this means is that the ADO will try every method for which it has access to retrieve the results. Obviously the process is burdened with the the onus of finding a suitable method.

    Using ADO

    As explained earlier ADO will try to guess and return the results if it can find a method. On the SQL 2005 Server there is a stored procedure called getEmployee in the Northwind database. For the CommandType property adCmdUnknown will be assigned, and for the CommandText property the name of this stored procedure will be assigned. The next code listing in the click event of a Command Button does exactly that as shown by the returned recordset that follows the code listing.

     

    Private Sub Command3_Click()
    'declare Connection, Command and RecordSet variables
    Dim oConn As ADODB.Connection
    Dim oCmd As ADODB.Command
    Dim rst As ADODB.Recordset
    'create new instances of the variables
    Set oConn = New ADODB.Connection
    Set oCmd = New ADODB.Command
    'Open the connection
    oConn.Open "Provider=SQLNCLI.1;Integrated Security=SSPI;" & _
    "Persist Security Info=False; Initial Catalog=Northwind;" & _
    "Data Source=Hodentekmysorian"
    oCmd.ActiveConnection = oConn
    'assigning adCmdUnknown to the CommandType
    oCmd.CommandType = adCmdUnknown
    'assign 'getEmployee' to the CommandText property
    oCmd.CommandText = "getEmployee"
    Set rst = oCmd.Execute
    'return only 3 fields
    Do Until rst.EOF
    Debug.Print (rst.Fields(0).Value & " , " & _
    rst.Fields(1).Value & " , " & _
    rst.Fields(2).Value & vbCrLf)
    rst.MoveNext
    Loop
    MsgBox (rst.Fields.Count)
    oConn.Close
    End Sub
    

    The result printed out to the immediate screen when the Command button is clicked is shown in the next paragraph. In this case at least ADO made a correct guess, but it must have searched for a table with a name when you compare it with the result from the stored procedure.

    Buchanan , 1955/03/04 , London
    

    Now the stored procedure getEmployee, when executed on the SQL 2005 Server, will return the following result.

    Summary

    This basic tutorial considers some of the ways the ADO's command object can be executed to query the database. When the CommandType was assigned the adCmdUnknown, ADO did return the results correctly, making the correct guess. The Parameters collection and the Parameter object have not been considered. The CommandTypes adCmdFile and adCmdTableDirect are not used with the Command object, but rather with the RecordSet object when it is open. The CommandType adCmdFile is used with a persisted recordset to a file, and uses the file name for the CommandText. The CommandType, adCmdTableDirect is also used with the open Recordset. The CommandText in this case will be intuitively the name of a table. It is interesting to note that when the CommandType is adCmdTable and the CommandText is assigned to the name of a table, the code MsgBox (cmd.CommandText) returns the full Select statement.


    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.

       · ADO command with several ways of calling it makes programming easier. The choices...
     

    DATABASE ARTICLES

    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005
    - Manipulating ADO Recordsets




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