Results 1 to 2 of 2

Thread: Connection Object - ADO

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Posts
    3

    Connection Object - ADO

    Hi,

    Please post the VB code required to call a Stored Procedure in SQL Server database with parameters using Connection Object of ADO.


    Thanks in advance.

    Regards,
    Nag

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    In this example, I have a SP set up like this;

    CREATE PROCEDURE sp_RunThisSP @Param1 VARCHAR(20), @Param2 VARCHAR(20) OUTPUT AS

    Code:
    Dim MyConn as New Adodb.Connection
    Dim MyCmd as New Adodb.Command
    
    'open the connection
    MyConn.Open "Provider=SQLOLEDB;Server=MYSERVER;Database=MYDB;","SA",""
    
    'start the command
    MyCmd.ActiveConnection = MyConn 
    MyCmd.CommandType = adCmdStoredProc
    MyCmd.CommandText = "sp_RunThisSP"
    
    'this next line is very handy - after setting the CommandText and
    'Connection you can use .PArameters.Refresh to pull back the 
    'required parameters for this SP from the SQL Server.
    MyCmd.Parameters.Refresh
    
    'note that Parameters(0) is the RETURN parameter of a SP
    'so the parametes you pass to it start with 1 (or, as below, you can use the @variable name)
    MyCmd.Parameters("@Param1")="PARAM1"
    
    MyCmd.Execute
    
    Msgbox "Output is " & MyCmd.Parameters("@Param2")
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width