Results 1 to 5 of 5

Thread: Calling a Stored procedure using ADO

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    32

    Question

    How do you call a Stored Procedure from a SQL 7.0 Database from Visual Basic?

  2. #2
    Lively Member
    Join Date
    Jun 2000
    Location
    A caravan park in the Midlands (UK)
    Posts
    101
    Code:
    dim moADODB as new ADODB.Connection
    dim mrsData as new ADODB.Recordset
      
    moADODB.Open msconnection
      
    mrsData.Open "exec sp_Collect " & lsParams, moADODB.Connection, adOpenStatic

    would do the trick
    Anakim

    It's a small world but I wouldn't like to paint it.

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    AngelaMicikas, hope this can help you.

    Code:
    Dim conn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim cmd As ADODB.Command
    
    Set conn = New ADODB.Connection
    conn.Open "Provider=SQLOLEDB;Data Source=Chris;Database=pubs;User Id=sa;password=;"
    
    Set cmd = New ADODB.Command
    cmd.CommandText = "<Your Store Procedure Name>"
    cmd.CommandType = adCmdStoredProc
    Set cmd.ActiveConnection = conn
    
    Set rs = cmd.Execute
    With rs
        'Do what ever you want here
    End With
    
    Set cmd = Nothing
    rs.Close
    Set rs = Nothing
    conn.Close
    Set conn = Nothing

  4. #4
    Addicted Member Babbalouie's Avatar
    Join Date
    Jan 2001
    Location
    On the bright, blue sea...
    Posts
    197
    This should do it...

    Dim objConn as ADODB.Connection
    Dim objCmd as ADODB.Command
    Dim objRs as ADODB.Recordset

    <Set and open connection object>
    Set objCmd = New ADODB.Command
    objCmd.CommandType = adCmdStoredProc
    objCmd.CommandText = " <StoredProcName>"
    objCmd.ActiveConnection = objConn
    Set objRs = objCmd.Execute

    If the Stored Procedure does not return a recordset, then the last line would be:

    objCmd.execute lRecReturned

    Where lRecReturned = number of records affected by executing the Stored Procedure...
    Building A Better Body Albeit Left Out Under Intense Extrapolation

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    32

    Wink THANKS ALL!! BIG HELP, HUGE!

    THANKS.

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