Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    193

    Unanswered: How to Pass a Parameter to Stored Procedure?

    How do you pass a parameter to a SQL Server stored procedure? All I need is to supply one date and a report is to output but I can't figure out how to get the date to the procedure. I can do is in SQL Server using Query Analyzer but I don't know VB well enough. I am using VB 6.0 for this. I created a very, very simple ADODC and one text box. I got VB to connect to the database all right but I can't set the text box's DataField property to the field I want because the parameter is missing.

    ddave

  2. #2
    Join Date
    Nov 2004
    Posts
    30
    Dim cmdobj As ADODB.Command
    Set cmdobj = New ADODB.Command
    Dim paramObj As ADODB.Parameter
    Set paramObj = New ADODB.Parameter

    With cmdobj
    Set paramObj = .CreateParameter("ReportDt", adDate, adParamInput, , your date value)
    .Parameters.Append paramObj
    Set paramObj = .CreateParameter("NextParam", adDate, adParamInput, , nextparameter)
    .Parameters.Append paramObj

    and you can keep adding so on

    .ActiveConnection = connection string
    .CommandType = adCmdStoredProc
    .CommandText = "your procedure name"
    .Execute


    End With

    I hope this explains it.

Posting Permissions

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