CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2000
    Location
    Germany, Franken
    Posts
    257

    ADO: Call Stored Procedure with out-parameters

    Hi,
    i have a stored procedure which i declared this way:
    CREATE PROCEDURE dbo.sp_anzRomaneProAutor @name text, @anz int output AS
    SELECT @anz= count(*)
    FROM Roman INNER JOIN
    Mitarbeiter ON Roman.Autor = Mitarbeiter.ID
    WHERE (Mitarbeiter.Name LIKE @name)
    GO
    Now i wrote a little basic-application to call this procedure:


    set rsPRAutor = cmPR.Execute
    set pmPRAutorName = cmPR.CreateParameter("@Name", adBSTR, adParamInput)
    cmPR.Parameters.Append pmPRAutorName

    set pmPRAutorAnz = cmPR.CreateParameter("@anz", adInteger, adParamOutput)
    cmPR.Parameters.Append pmPRAutorAnz
    rsPRAutor.MoveFirst
    While (Not rsPRAutor.EOF)
    'Anzahl der Romane pro Autor lesen
    cmPR.CommandText = "sp_anzRomaneProAutor"
    cmPR.CommandType = adCmdStoredProc
    pmPRAutorName.Value = rsPRAutor.Fields(0)
    set rsPRAnz = cmPR.Execute
    rsPRAutor.MoveNext
    Wend



    but if i watch thr pmPrAutorAnz and the rsPRAnz-Object there a no values field in. The count of fields of rsPRAnz is 0 and pmPrAutorAnz is also 0.
    What have i done wrong? How can i call a stored procedure within VB and receive the result of the procedure?

    Thanks

    akademos


  2. #2
    Join Date
    May 2000
    Location
    Canada
    Posts
    32

    Re: ADO: Call Stored Procedure with out-parameters

    Dim con as new adodb.connection
    dim rst as new adodb.recordset

    con.Open "Driver{SQLServer};Server=servername;Uid=userID;Pwd=password;Database=DBName"

    set rst = con.execute("sp_anzRomaneProAutor " & "'" & name_text & "'"
    if (rst.eof = false or rst.bof = false) then
    do
    'what ever you want to do with the record
    rst.movenext
    loop until rst.eof = true
    end if


    Rate it, if Helps




  3. #3
    Join Date
    Mar 2000
    Location
    Germany, Franken
    Posts
    257

    Re: ADO: Call Stored Procedure with out-parameters

    This doesn't work also:
    1. I have a second parameter which is a out-parameter
    2. In my original code it tells me that my recordset isn't opened so i can't use funktions such as .EOF, .MoveNext or similar

    thanks

    akademos


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

Featured