[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

ObjectDatasource: Can't get the value of output parameter in the Updated event

Asked by Curlew in Miscellaneous Web Development, Programming for ASP.NET

Tags: ASP.NET Web Development

I am unable to get the value of an OUTPUT parameter in the objectDataSource Updated Event (ASP.NET (VS 2005)). The ObjectDataSource is executing a Stored Procedure to do the update.

When I go to do the update from my DetailsView control, I receive the following message:
    Object variable or With block variable not  set.
 intRetVal =   e.OutputParameters("ReportForThisOfficer").Value
The SP update is working fine, but I want to display a message based on the value of my output Parameter.
I thought that Output parameters are added to the output parameters collection after the execution of the Stored Procedure. However, the Updated event does not get the output parameter value when I do:

   intRetVal = e.OutputParameters("ReportForThisOfficer").Value

 Moreover,  e.OutputParameters.Count returns 0.  

Therefore, I am really missing how to get the output parameter value, and I would like to know when the outputParameters collection adds my output parameter and how is it done (done implicitly/behind the hood?)
I am using a DataReader in the ods class, and the data is displayed in a DetailsView control.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
Updated Event:  called from OnUpdated in the ObjectDataSource:
 
  Protected Sub ods1_Updated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ods1.Updated
 
        Dim intRetVal As Integer = -1
        Dim OutputParametersCount As Integer = -1
        OutputParametersCount = e.OutputParameters.Count
        lblUpdateResult.Text = CStr(OutputParametersCount)
 
        intRetVal = e.OutputParameters("ReportForThisOfficer").Value
 
        If intRetVal = 5 Then
            lblUpdateResult.Text = "Message #1 &"
        ElseIf intRetVal = 7 Then
            lblUpdateResult.Text = " Message #2 &."
        ElseIf intRetVal = 6 Then
             e.ExceptionHandled = True
            lblUpdateResult.Text = " Message #2 &."
 
        Else
            lblUpdateResult.Text = "The expected values not returned by SP"
        End If
    End Sub
 
ObjectDataSource:
 
<asp:ObjectDataSource 
    ID="ods1"
    onobjectcreating="OfficerIDObjectCreating"
    SelectMethod="GetOfficersForApproval"
    UpdateMethod="UpdateOfficersForApproval"
    OnUpdated="ods1_Updated"
    typename="TSSSp1A.clsTSSLevels1A"
     runat="server">
     
     <UpdateParameters>
     <asp:QueryStringParameter
       Name="OfficerID"      
       Type="Int32"/>       
     <asp:Parameter
        Name="CertificationNo"
        Type="Int32"/>  
     <asp:Parameter
        Name="UserType"
        Type="Int16"/>
       <asp:Parameter
         Name="Username"
         Type="String"/>
       <asp:Parameter
         Name="MyPassword"
         Type="String"/>
        <asp:Parameter
          Name="ReportForThisOfficer"
          Direction="Output"
          Type="Int32" />
     
     </UpdateParameters>
    
    </asp:ObjectDataSource>
 
Class Code: ( see ObjectDataSource (above) typename="TSSSp1A.clsTSSLevels1A")
 
       Public Function UpdateOfficersForApproval(ByVal OfficerID As Int32, ByVal CertificationNo As Int32, ByVal UserType As Int16, ByVal UserName As String, ByVal MyPassword As String, ByVal ReportForThisOfficer As Int32)
            Dim con As New SqlConnection(_conString)
            Dim cmd As New SqlCommand("UpdateOfficersForApproval", con) 
            cmd.CommandType = CommandType.StoredProcedure
 
            cmd.Parameters.AddWithValue("@OfficerID", OfficerID)
            cmd.Parameters.AddWithValue("@CertificationNo", CertificationNo)
            cmd.Parameters.AddWithValue("@UserType", UserType)
            cmd.Parameters.AddWithValue("@Username", UserName)
            cmd.Parameters.AddWithValue("@MyPassword", MyPassword)
            cmd.Parameters.Add("@ReportForThisOfficer", Data.SqlDbType.Int)
            cmd.Parameters("@ReportForThisOfficer").Direction = Data.ParameterDirection.Output
 
            con.Open()
            Return cmd.ExecuteReader(CommandBehavior.CloseConnection)           
        End Function
 
Stored Procedure:
 
ALTER PROCEDURE [dbo].[UpdateOfficersForApproval] 
	-- Add the parameters for the stored procedure here
	@OfficerID int,
    @CertificationNo int, 
	@UserType int,
	@Username varchar(75),
	@MyPassword varchar(50),
	@ReportForThisOfficer int OUTPUT
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
    IF EXISTS
    (
   SELECT * FROM Officer
   WHERE CertNo = @CertificationNo 
   AND UserType = 1  -- Another officer w/ same CertNo has been approved by the TSS Admin. 
 
  ) 
  BEGIN
	
       SET @ReportForThisOfficer = 5 -- means we have a duplicate Certification No and cannot do the update
	   RETURN 
 
  END 
	
  ELSE
 
  BEGIN
    
    		Update Officer 
		SET UserType=@UserType, Username=@Username, MyPassword=@MyPassword
		Where OfficerID=@OfficerID
		IF(@@ERROR <>0) GOTO ERR_HANDLER    
 
		SET @ReportForThisOfficer =  7  -- succesful update
		RETURN 
 
    END
  END
	  
    ERR_HANDLER:
	 PRINT 'An Error occurred in the Update'
 
      SET @ReportForThisOfficer = 6  -- MEANS ERROR OCCURED IN THE update
	  RETURN
Attachments:
 
ObjectDataSource code
 
[+][-]09/02/09 11:58 AM, ID: 25244366Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Miscellaneous Web Development, Programming for ASP.NET
Tags: ASP.NET Web Development
Sign Up Now!
Solution Provided By: davrob60
Participating Experts: 1
Solution Grade: A
 
[+][-]08/31/09 01:48 PM, ID: 25226399Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/31/09 03:05 PM, ID: 25226952Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/01/09 08:24 AM, ID: 25232536Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/01/09 08:32 AM, ID: 25232640Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/01/09 11:41 AM, ID: 25234613Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/01/09 12:18 PM, ID: 25234940Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/01/09 12:53 PM, ID: 25235254Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/01/09 05:07 PM, ID: 25237276Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/02/09 07:54 AM, ID: 25241689Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/02/09 08:04 AM, ID: 25241799Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/02/09 11:48 AM, ID: 25244244Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/02/09 01:45 PM, ID: 25245526Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/02/09 01:49 PM, ID: 25245569Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/02/09 04:34 PM, ID: 25246694Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625