Results 1 to 16 of 16

Thread: [RESOLVED] Problems with a SPROC

  1. #1

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Resolved [RESOLVED] Problems with a SPROC

    I am trying to create a SPROC and then access it via VB6. I am able to create the SPROC by using the following code:

    VB Code:
    1. 'Stored Procedure
    2. USE IADATA
    3. DROP PROCEDURE dbo.GetCasesTeam
    4. GO
    5. Create Procedure dbo.GetCasesTeam
    6.     @InvUnit VarChar(100),
    7.     @Team VarChar(100) OutPut,
    8.     @Count int Output
    9.  
    10. As
    11.  
    12.     SELECT @Team = dbo.INCIDENTS.INV_TITLE, @Count = Count(IA_ADM.PRIMARY_CASE_REC.CASENUM)
    13.     FROM dbo.INCIDENTS INNER JOIN IA_ADM.PRIMARY_CASE_REC ON
    14.     dbo.INCIDENTS.INCNUM = IA_ADM.PRIMARY_CASE_REC.PC_INCNUM
    15.     WHERE dbo.INCIDENTS.INV_UNIT in('@InvUnit') AND
    16.     dbo.INCIDENTS.STATUS in('Active','Suspended')
    17.     GROUP BY dbo.INCIDENTS.INV_TITLE
    18.     ORDER BY Count(IA_ADM.PRIMARY_CASE_REC.CASENUM);
    19.  
    20. RETURN @@ERROR

    But when I run the following code I get an error on the .Execute Line, "Type name is invalid". WHat am I doing wrong? Also when I try to use adVarChar in the create Parameter property I get an "Parameter Object is improperly define. Incoonsistant or incomplete information was provided" error
    VB Code:
    1. 'VB Code
    2. Private Sub Form_Load()
    3.  
    4. Dim adoConn As ADODB.Connection
    5. Dim adoCmd As ADODB.Command
    6.  
    7. Set adoConn = New ADODB.Connection
    8. adoConn.Open connString
    9.  
    10. Set adoCmd = New ADODB.Command
    11. With adoCmd
    12.     Set .ActiveConnection = adoConn
    13.     .CommandText = "GetCasesTeam"
    14.     .CommandType = adCmdStoredProc
    15.     .Parameters.Append .CreateParameter("RetVal", adInteger, adParamReturnValue)
    16.     .Parameters.Append .CreateParameter("InvUnit", adVariant, adParamInput) '<==Error when I use adVarChar
    17.     .Parameters.Append .CreateParameter("Team", adVariant, adParamOutput, 100)
    18.     .Parameters.Append .CreateParameter("Count", adInteger, adParamOutput)
    19.     .Parameters("InvUnit").Value = "Unit A"
    20.  
    21.     .Execute , , adExecuteNoRecords 'the stored procedure does not return any records '<=== Error "Type name is invalid"
    22.  
    23.     Debug.Print .Parameters("Team").Value, .Parameters("Count").Value
    24. End With

    End Sub

    Thanks!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Problems with a SPROC

    VB Code:
    1. .Parameters.Append .CreateParameter("RetVal", adInteger, adParamReturnValue)
    2.     .Parameters.Append .CreateParameter("InvUnit", adVarChar, adParamInput, 100) 'You MUST provide the max len of the parameter when using a varchar
    3.     .Parameters.Append .CreateParameter("Team", adVarChar, adParamOutput, 100)
    4.     .Parameters.Append .CreateParameter("Count", adInteger, adParamOutput)
    5.     .Parameters("InvUnit").Value = "Unit A"

    One simple change.... ok, two.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Problems with a SPROC

    techgnome,
    Thanks alot for your help, it work like a charm! Now the SPROC is returning 4 records how step through each of the records in the ADODB.Command object similiar to rs.MoveNext in the recordset?

    Thanks!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Problems with a SPROC

    If you want the 4 rows to come back do not do the:

    SELECT @Team = dbo.INCIDENTS.INV_TITLE, @Count = Count(IA_ADM.PRIMARY_CASE_REC.CASENUM)

    but instead do...

    SELECT dbo.INCIDENTS.INV_TITLE, Count(IA_ADM.PRIMARY_CASE_REC.CASENUM)

    Then do a :

    Set rsObject = .Execute

    That will give you the 4 rows as a recordset.

    There is no way to return 4 parameter pairs.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Problems with a SPROC

    Steve,
    Thanks, what type of object is "rsObject"?

    VB Code:
    1. Set rsObject = .Execute

    ADODB.Command or ADODB.Recordset?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  6. #6

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Problems with a SPROC

    Steve,
    I assumed that the RSObject is a Recordset but it isn't being assigned to the recordset. WHat am I doing wrong?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Problems with a SPROC

    Did you change the SPROC to remove the OUTPUT parameters?

    And change the select to no longer fill the variables?

    To test the SPROC you can EXECUTE it in QUERY ANALYZER...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Problems with a SPROC

    Quote Originally Posted by szlamany
    Did you change the SPROC to remove the OUTPUT parameters?
    Yes

    Quote Originally Posted by szlamany
    And change the select to no longer fill the variables?
    Yes

    Quote Originally Posted by szlamany
    To test the SPROC you can EXECUTE it in QUERY ANALYZER...
    It works fine it returns the appropriate number of records, but my question is how do I access them via code? Is it similiar to a Recordset:

    VB Code:
    1. For a = 1 to rs.RecordCount
    2.      MsgBox  rs.Fields(1).Value
    3. Next a

    Thanks
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  9. #9

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Problems with a SPROC

    Ok, I figured out my problem, the rs.RecordCount propert is returning -1 so my For Next loop was failing. Now my next question is how do I submit more than one INV_UNIT:

    VB Code:
    1. USE IADATA
    2. DROP PROCEDURE dbo.GetCasesTeam
    3. GO
    4. Create Procedure dbo.GetCasesTeam
    5.     @InvUnit VarChar(100)
    6.  
    7. As
    8.  
    9.     SELECT dbo.INCIDENTS.INV_TITLE, Count(IA_ADM.PRIMARY_CASE_REC.CASENUM)
    10.     FROM dbo.INCIDENTS INNER JOIN IA_ADM.PRIMARY_CASE_REC ON
    11.     dbo.INCIDENTS.INCNUM = IA_ADM.PRIMARY_CASE_REC.PC_INCNUM
    12.     WHERE dbo.INCIDENTS.INV_UNIT in(@InvUnit) AND
    13.     dbo.INCIDENTS.STATUS in('Active','Suspended')
    14.     GROUP BY dbo.INCIDENTS.INV_TITLE
    15.     ORDER BY Count(IA_ADM.PRIMARY_CASE_REC.CASENUM);

    When I run the SP in the Query Analyzer like this:

    VB Code:
    1. Execute GetCasesTeam @InvUnit="Unit A, Unit B, Unit C"
    No records are returned but if I do them individually they all return records. I know I am doing something stupid, but what?!?!??

    Thanks!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  10. #10

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Problems with a SPROC

    If I change my SP to the following:
    VB Code:
    1. USE IADATA
    2. DROP PROCEDURE dbo.GetCasesTeam
    3. GO
    4. Create Procedure dbo.GetCasesTeam
    5. As
    6.  
    7.     SELECT dbo.INCIDENTS.INV_TITLE, Count(IA_ADM.PRIMARY_CASE_REC.CASENUM)
    8.     FROM dbo.INCIDENTS INNER JOIN IA_ADM.PRIMARY_CASE_REC ON
    9.     dbo.INCIDENTS.INCNUM = IA_ADM.PRIMARY_CASE_REC.PC_INCNUM
    10.     WHERE dbo.INCIDENTS.INV_UNIT in('Unit A', 'Unit B', 'Unit C') AND
    11.     dbo.INCIDENTS.STATUS in('Active','Suspended')
    12.     GROUP BY dbo.INCIDENTS.INV_TITLE
    13.     ORDER BY Count(IA_ADM.PRIMARY_CASE_REC.CASENUM);

    and then execute it it returns the required records:

    VB Code:
    1. Execute GetCasesTeam
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  11. #11

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: [RESOLVED] Problems with a SPROC

    Thanks to all, it is working now, I just needed to submit my query string correctly. Thaks to all again!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] Problems with a SPROC

    The -1 form the recordscount is because a server side cursor was being used. -1 is actualy good, it means there are records, we just don't know how many.... three ways around this:
    1) use a client side cursor. This will force the recordset to actualy populate itself.
    2) "Jiggle the recordset" - a technique I've used inthe past. Do a .MoveLast followed by a .MoveFirst will get the records. After that .RecordCount will be correct
    3) Use a while loop instead of a for loop:
    VB Code:
    1. Do while not rstMine.EOF
    2.  'Do looping stuff
    3.   rstMine.MoveNext
    4. Loop


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [RESOLVED] Problems with a SPROC

    See this link for a trick on how to pass "," separated values in a SPROC parameter and then WHERE-clause them...

    http://www.vbforums.com/showpost.php...97&postcount=4

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  14. #14

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: [RESOLVED] Problems with a SPROC

    techgnome and szlamany thank you very much!!!!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  15. #15
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] Problems with a SPROC

    The bill is in the mail....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  16. #16

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: [RESOLVED] Problems with a SPROC

    Sorry. . .
    Attached Images Attached Images  
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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