Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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


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.

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"
        if valParam = -2 then
          lblMessage.Text = "Agreement ID already exists"
          lblMessage.Text = "Agreement was created"
        End If
      end if
  End Sub

and parts of ASPX page with FromView:

 InsertCommand="spNew_Agreement" OnInserted="OnInserted">

  <asp:ControlParameter Name="Acct_Name" ControlID="txtAcct_Name" />
  <asp:Parameter Name="acct_id" Type="string" />
  <asp:Parameter Name="agreement_id" Type="string" />
  <asp:Parameter Name="return_value" Type="int32" Direction="ReturnValue" />
Reply With Quote
  #2 (permalink)  
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

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.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 02:42 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.