Database
  Home arrow Database arrow Page 5 - 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 
IBM Developerworks
 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

    Ajax Application Generator Generate database 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 adCmdTable
    (Page 5 of 6 )

    On SQL 2005 Server

    When the CommandType is assigned to the adCmdTable, what is returned is equivalent to returning all the columns from the named table as shown in the next picture.

    Using ADO

    In order to return the same records using ADO, the properties CommandType and CommandText have to be appropriately 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 Command2_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
    'set command's CommandType property to adCmdTable
    oCmd.CommandType = adCmdTable
    'set the Command's Command text property to a name of a table
    'as a string
    oCmd.CommandText = "Employees"
    Set rst = oCmd.Execute
    'note although all 18 columns are returned, only three of them are
    'printed to the immediate screen.
    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)
    MsgBox (oCmd.CommandText)
    oConn.Close
    End Sub
    

    The result printed out to the immediate screen when the Command button is clicked is shown in the next paragraph.

    1 , Davolio , Nancy
    2 , Fuller , Andrew
    3 , Leverling , Janet
    4 , Peacock , Margaret
    5 , Buchanan , Steven
    6 , Suyama , Michael
    7 , King , Robert
    8 , Callahan , Laura
    9 , Dodsworth , Anne
    

    More Database Articles
    More By Jayaram Krishnaswamy


       · 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 1 hosted by Hostway