473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Return value from stored procedure is "nothing"

10
I have a stored procedure running in SQL Server 2000 which returns a value
when I run it in SQL Server Management Studio 2008 (SMS). I have also tested
it in SQL Server 2000 Query Analyzer with the same result. However, when I
run it with VB.Net 2010 I get "nothing" as the value of the return parameter:
cmd.Parameters("@ReturnCount").Value.
How do I get a value back? The parameter I am testing on is @ReturnCount.
I will need it to work for the return code also - @ReturnCode.

I have searched the web and found quite a few examples and tried them, but
they do not work with this code.

(I have simplified the procedure for testing. I am using dynamic SQL
because the SELECT in the actual procedure uses a parameter on the FROM
clause. I use sp_executesql in order to get a return value from the
dynamic SQL.)

Expand|Select|Wrap|Line Numbers
  1. /*
  2. Test procedure:
  3.  
  4. declare @ReturnCount int
  5. declare @ReturnCode int
  6. exec dbo.spSampGroupPRptgS 'mltpsdb02',
  7.                            'prodreporting',
  8.                            '''100000015''',
  9.                            @ReturnCode output
  10. */
  11.  
  12. if exists (select * 
  13.   from dbo.sysobjects 
  14.   where id = object_id(N'dbo.spSampGroupPRptgS') and 
  15.              OBJECTPROPERTY(id, N'IsProcedure') = 1)
  16.     drop procedure dbo.spSampGroupPRptgS
  17. GO
  18.  
  19. CREATE PROCEDURE dbo.spSampGroupPRptgS
  20.   ( @PRptgDBServer         varchar(30),
  21.     @PRptgDatabase         varchar(30),
  22.     @GroupParentIDs        varchar(4000),
  23.     @ReturnCode            int output
  24.     )
  25. AS 
  26. SELECT @ReturnCode = 0
  27. DECLARE @SQL nvarchar(4000)
  28. DECLARE @ReturnCount int
  29.  
  30. SELECT @SQL=
  31. N'SELECT @ReturnCount = Count(*)
  32. FROM GroupTestData
  33. WHERE Parent_Group_Id in ('+@GroupParentIDs+')
  34. '
  35.  
  36. DECLARE @params nvarchar(500)
  37.  
  38. SET @params = 
  39.   N'@PRptgDBServer         nvarchar(30),
  40.     @PRptgDatabase         nvarchar(30),
  41.     @GroupParentIDs        nvarchar(4000),
  42.     @ReturnCount           int output'
  43.  
  44. EXEC sp_executesql @SQL,
  45.                    @params,
  46.                    @PRptgDBServer  = @PRptgDBServer,
  47.                    @PRptgDatabase  = @PRptgDatabase,
  48.                    @GroupParentIDs = @GroupParentIDs,
  49.                    @ReturnCount    = @ReturnCount OUTPUT
  50.  
  51. SELECT @ReturnCount
  52.  
  53. GO
  54.  
  55. ----------------------------------------------------------
  56.  
  57. Public Function GetGroupParents(ByRef GroupParentsArg(,) As String) As Boolean
  58.  
  59.     Dim cmd As New SqlCommand
  60.     Dim drGroupParents As SqlDataReader
  61.     Dim cnString As String = gConnectionString
  62.     Dim cn As New SqlConnection(cnString)
  63.     Dim MaxRowCount As Integer
  64.     Dim RowCount As Integer
  65.  
  66.     GetGroupParents = True
  67.  
  68.     Try
  69.       cmd.CommandTimeout = 1200
  70.       cmd.CommandText = "dbo.spSampGroupPRptgS"
  71.       cmd.CommandType = CommandType.StoredProcedure
  72.  
  73.       cmd.Parameters.Add("@PRptgDBServer", SqlDbType.VarChar, 30).Value = gPRptgDBServer
  74.       cmd.Parameters.Add("@PRptgDatabase", SqlDbType.VarChar, 30).Value = gPRptgDatabase
  75.       cmd.Parameters.Add("@GroupParentIDs", SqlDbType.VarChar, 4000).Value = gGroupParentIDs
  76.  
  77.       cmd.Parameters.Add("@ReturnCount", SqlDbType.Int)
  78.       cmd.Parameters("@ReturnCount").Direction = ParameterDirection.ReturnValue
  79.       cmd.Parameters.Add("@ReturnCode", SqlDbType.Int)
  80.       cmd.Parameters("@ReturnCode").Direction = ParameterDirection.Output
  81.  
  82.       ' Call spSampGroupPRptgS to get Parent Group Name, Product ID's, and Group ID's
  83.       cmd.Connection = cn
  84.       cmd.CommandType = CommandType.StoredProcedure
  85.       cn.Open()
  86.       drGroupParents = cmd.ExecuteReader
  87.  
  88.       If drGroupParents.HasRows Then
  89.  
  90.         MaxRowCount = CInt(cmd.Parameters("@ReturnCount").Value)
  91.         MessageBox.Show("MaxRowCount: " & MaxRowCount, Application.ProductName)
  92.  
  93.         ReDim GroupParentsArg(MaxRowCount, 4)
  94.  
  95.         RowCount = 0
  96.         While drGroupParents.Read()
  97.           GroupParentsArg(RowCount, 0) = Trim(drGroupParents.Item("ParentGroupId").ToString)
  98.           GroupParentsArg(RowCount, 1) = Trim(drGroupParents.Item("ParentGroupName").ToString)
  99.           GroupParentsArg(RowCount, 2) = Trim(drGroupParents.Item("ProductId").ToString)
  100.           GroupParentsArg(RowCount, 3) = Trim(IIf(Not IsDBNull(drGroupParents.Item("GroupId")), _
  101.                                              drGroupParents.Item("GroupId"), "").ToString)
  102.           RowCount += 1
  103.         End While
  104.       Else
  105.         If Not gSilentMode Then
  106.           MessageBox.Show("No Group ProdReporting Data Found", _
  107.                           Application.ProductName & " No Group ProdReporting Data Found")
  108.         End If
  109.         InformationHandler("No Group ProdReporting Data Found", "")
  110.         GetGroupParents = False
  111.         Exit Function
  112.       End If
  113.  
  114.     Catch ex As Exception
  115.       ErrorHandler("DataAccessModule.GetGroupParents", "", ex)
  116.       GetGroupParents = False
  117.     End Try
  118.  
  119.   End Function
  120.  
  121.  
Apr 17 '12 #1
1 2798
ck9663
2,878 Expert 2GB
If your SP is returning the result in query analyzer window and not in your front-end, then the problem is in your front-end. Go to .Net forum and post the portion where you access the returned result set of your SP.

Good Luck!!!


~~ CK
Apr 19 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ¤ Alias | last post by:
I have a function named getID3info (lvwDiscInfo.SelectedItem). What is the difference between getID3info (lvwDiscInfo.SelectedItem) and Call getID3info(lvwDiscInfo.SelectedItem) ?
0
by: Luis | last post by:
I'm using a SQL Server 2000 stored procedure similar to the one below to upload data to a database. This data is collected from the user on a number of asp pages and stored in session variables...
1
by: Don Leverton | last post by:
Hi Folks, I'm still in the process of rewriting my Parts Inventory application, and still using good old Access97 to do it. I'm attempting to modify Allen Browne's code from:...
388
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's...
2
by: Julio Allegue | last post by:
I am getting the wrong Count(*) on vb.net using the ExecuteScalar . It returns all the rows. It doesn't seem to look at the WHERE clause. At the same time, I am getting the correct count on "SQL...
13
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
9
by: Cao Yi | last post by:
Hi, here's a fract of codes, and what's the line "scanf("%lf%*", &cvi)" doing? ============================= do { printf("\nCoefficient: "); scanf("%lf%*", &cvi); getchar(); } while (cvi <=...
0
by: cfriedalek | last post by:
I'm writing a python script using win32com to call a 3rd party program via its VBS based API. In VBS a query to get some plot data goes like this: Plot.QueryBegin datacode, Nothing What is...
0
by: Larry Bud | last post by:
Using XML serializer, if an XML field is missing, then the value in the object is Nothing. Is there a slick way of converting a "Nothing" to an empty string without doing is if x is nothing...
0
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.