Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 14th, 2008, 01:11 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Capturing RETURNVALUE from SP using FormView

Hello

I'm using FromView to Insert record into a DB. My SP checks for the existence and returns -1 if record already exists. I know that my SP returns -1 but how do I capture that into FormView and display error message to the user? All I get is the "Agreement was created" regardless of what SP returns.
Your help is appreciated.

Mark
Here is the code I'm using:
Protected Sub OnInserted(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceStatusEvent Args)
        Dim retValParam As New SqlParameter("@RETURN_VALUE", SqlDbType.Int)
        retValParam.Direction = ParameterDirection.ReturnValue


        Dim valParam As Integer = Convert.ToInt32(retValParam.Value)
        If valParam = -1 Then
          lblMessage.Text = "The Account ID is not valid"
        Else
        if valParam = -2 then
          lblMessage.Text = "Agreement ID already exists"
          else
          lblMessage.Text = "Agreement was created"
        End If
      end if
  End Sub

and parts of ASPX page with FromView:

 InsertCommand="spNew_Agreement" OnInserted="OnInserted">

  <FilterParameters>
  <asp:ControlParameter Name="Acct_Name" ControlID="txtAcct_Name" />
  </FilterParameters>
  <InsertParameters>
  <asp:Parameter Name="acct_id" Type="string" />
  <asp:Parameter Name="agreement_id" Type="string" />
  <asp:Parameter Name="return_value" Type="int32" Direction="ReturnValue" />
  </InsertParameters>
 
Old April 15th, 2008, 04:40 AM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Of course you can't get return value that way. You are creating new parameter _after_ the procedure has been executed. You should check SqlDataSourceStatusEventArgs class and SqlDataSourceStatusEventArgs.Command property from MSDN.




Similar Threads
Thread Thread Starter Forum Replies Last Post
'event.returnValue=false' equivalent for Firefox nitinp ASP.NET 2.0 Basics 0 February 5th, 2007 11:56 AM
Capturing images sammy7 J2EE 0 December 22nd, 2006 03:11 AM
UsingJavaScript ReturnValue param99 ASP.NET 1.0 and 1.1 Professional 3 November 10th, 2006 05:49 AM
exec sp within another sp collie SQL Server 2000 1 December 22nd, 2004 05:46 AM
Can a SP run another SP as sa? dbradley SQL Server 2000 0 July 17th, 2003 08:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.