Results 1 to 12 of 12

Thread: *Resolved* Help With Calling a SP from VB.Sincere Thanks to VBForums :)

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    86

    Unhappy *Resolved* Help With Calling a SP from VB.Sincere Thanks to VBForums :)

    Here is the code that I am working on : I need to call the Stored Procedure from VB and fetch the data. Please tell me where I am going wrong :

    VB Code:
    1. Public Function RS1(ByVal pId As Integer, ByVal cId As Integer, ByVal FrmDt As String, ByVal ToDt As String) As Integer
    2.  
    3.     Dim adoCon As New ADODB.Connection
    4.     Dim adoRset As New ADODB.Recordset
    5.     Dim adoCmd As New ADODB.Command
    6.     Dim retCode As Integer
    7.     Dim rStr As String  
    8.  
    9.     On Error GoTo ErrorHandler
    10.        
    11.     With adoCmd
    12.         .ActiveConnection = connString
    13.         .CommandType = adCmdStoredProc
    14.         .CommandText = "proc_name"
    15.          
    16.         .Parameters.Append .CreateParameter("@retrn", adInteger, adParamReturnValue, ,0)
    17. .Parameters.Append .CreateParameter("@output", adInteger, adParamOutput, , 999)
    18.          
    19.         .Parameters.Append .CreateParameter("@p_id", adInteger, adParamInput, , pId)
    20.         .Parameters.Append .CreateParameter("@c_id", adInteger, adParamInput, , cId)
    21.         .Parameters.Append .CreateParameter("@frm_dt", adVarChar, adParamInput, 12, FrmDt)
    22.         .Parameters.Append .CreateParameter("@to_dt", adLongVarChar, adParamInput, 12, ToDt)
    23.      End With
    24.        
    25.      Set adoRset = adoCmd.Execute
    26.      Do While (Not adoRset Is Nothing)
    27.           If adoRset.State = adStateClosed Then Exit Do
    28.           While Not adoRset.EOF
    29.               For i = 0 To adoRset.Fields.Count - 1
    30.                   rStr = rStr & " : " & adoRset(i)
    31.               Next i
    32.               Debug.Print Mid(rStr, 3, Len(rStr))
    33.               adoRset.MoveNext
    34.               rStr = ""
    35.           Wend
    36.           Set adoRset = adoRset.NextRecordset
    37.           Loop
    38.      
    39.       retCode = adoCmd.Parameters("@retrn").Value
    40.       Debug.Print "Return: " & adoCmd.Parameters ("@retrn").Value        
    41.       GoTo Shutdown
    42.      
    43.    
    44. ErrorHandler:
    45.  
    46.     Set adoCmd = Nothing
    47.     RS1 = -100
    48.  
    49. Shutdown:
    50.           Set adoCmd = Nothing
    51.           Set adoRset = Nothing
    52.           Set adoCon = Nothing
    53.  
    54. End Function
    55.  
    56. Public Function PpltRS() As Integer
    57.          RS1 p1_Id, c1_Id, Frm_Dt, To_Dt
    58. End Function
    Piece of SQL code :
    Code:
    create procedure proc_name
    @p_id 	int=null,
    @cr_id	int=null,
    @frm_dt	varchar(12),
    @to_dt	varchar(12),
    @retrn	int output
    as
    Also,how can I call this function at a click of a button ?

    Thanks.Any help is appreciated .
    Last edited by NewbieVB2003; Jun 6th, 2003 at 07:23 PM.

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