Database
  Home arrow Database arrow Page 4 - ADO and the Command Object
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 / 10
    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
     
     
    ADVERTISEMENT


    ADO and the Command Object - CommandType is adCmdStoredProc


    (Page 4 of 6 )

    On SQL 2005 Server

    Again for comparison purposes we take a look at the following stored procedure on the SQL 2005 Server called the getCityEmployee. This stored procedure when executed on the server returns the result which consists of all the employees from "London" as shown.

    If you take a look at the script of this procedure shown in the next listing, you notice that it takes no arguments, but returns the results of a Select query. It's basically a select statement created as a stored procedure.

    Use Northwind
    Go
    create procedure [dbo].[getCityEmployee]
    as
    select LastName, BirthDate, City 
    from Employees where City='London'
    Go
    

    Using ADO

    For this case, again the proper values for the CommandType and CommandText have to be set appropriately as shown in the next code listing in the click event of a command button. In coding this you must use the intellisense automatically provided as shown.

     

    Private Sub Command1_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 the CommandType to stored procedure
    oCmd.CommandType = adCmdStoredProc
    'set the command text to the name of the stored procedure
    'on the server as a string
    oCmd.CommandText = "getCityEmployee"
    Set rst = oCmd.Execute
    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.

    Buchanan , 1955/03/04 , London
    Suyama , 1963/07/02 , London
    King , 1960/05/29 , London
    Dodsworth , 1966/01/27 , London 

    More Database Articles
    More By Jayaram Krishnaswamy


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

    DATABASE ARTICLES

    - Building Applications with Anonymous Types
    - A Closer Look at Anonymous Types
    - Programming with Anonymous Types
    - Converting Your Excel Worksheet into a Worki...
    - Excel Reference
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek