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>
|