I'm using asp.net 4.5 and c# for my codebehind
I have a SqlDataSource that is not bound to a control; the purpose is - based on an action button i'll call a stored procedure. (I have another sqldatasource that fills a table, based on clicking a button w/in a row of that gridview the SP is supposed to execute using parameters from the gridview)
I've messed around with the definition of the data source
My questions/plea for help are:
- Is my SP being called at all with DataBind ? (and maybe my parameters are ill formed) - or does it need an object on the asp page to be tied to? Is there a better way to call the sp?
- How do I get/see the ReturnValue?
- How can I see the SQL output? (or maybe I should just make that an input/output parameter of the SP)
Advance thanks for any help.
((latest version of asp sql source - with exec and parms in the select))
<asp:SqlDataSource ID="sqlAlterStatus" runat="server" ConnectionString="<%$ ConnectionStrings:BOS_data.Prod %>"
SelectCommand="EXEC @ReturnValue = Customer_Contact_output.sp_PCC_Channel_Strategy_ltrs_alter_action_campaign_wth @FILE_ID, @Campaign_Name, @UPSCheck, @ACTION, @ECODE, @FULLNAME"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="FILE_ID" Type="Int32" />
<asp:Parameter Name="Campaign_Name" Type="String" />
<asp:Parameter Name="UPSCheck" Type="Boolean" />
<asp:Parameter Name="ACTION" Type="Byte" />
<asp:Parameter Name="ECODE" Type="String" />
<asp:Parameter Name="FULLNAME" Type="String" />
<asp:Parameter Name="ReturnValue" Type="Int16" Direction="ReturnValue" />
</SelectParameters>
</asp:SqlDataSource>
((and my original - parms not in select))
<asp:SqlDataSource ID="sqlAlterStatus" runat="server" ConnectionString="<%$ ConnectionStrings:BOS_data.Prod %>"
SelectCommand="Customer_Contact_output.sp_PCC_Channel_Strategy_ltrs_alter_action_campaign_wth" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="FILE_ID" Type="Int32" />
<asp:Parameter Name="Campaign_Name" Type="String" />
<asp:Parameter Name="UPSCheck" Type="Boolean" />
<asp:Parameter Name="ACTION" Type="Byte" />
<asp:Parameter Name="ECODE" Type="String" />
<asp:Parameter Name="FULLNAME" Type="String" />
<asp:Parameter Name="ReturnValue" Type="Int16" Direction="ReturnValue" />
</SelectParameters>
</asp:SqlDataSource>
The SP is mostly simple - definition:
ALTER PROCEDURE [Customer_Contact_output].[sp_PCC_Channel_Strategy_ltrs_alter_action_campaign_wth]
@FILE_ID BIGINT
, @Campaign_Name VARCHAR(50)
, @UPSCheck BIT
, @ACTION TINYINT
, @ECODE VARCHAR(6)
, @FULLNAME VARCHAR(255)
after validation/updates/inserts there is a simple select (for a message - which I can't figure how to capture either) and return value -- like this:
SELECT 'FAIL - INVALID PARAMETER (CAMPAIGN NAME)' AS RETURN_MESSAGE
RETURN 0 -- FAIL
I'm trying to call the SP from the RowCommand on the gridview ((I've also altered this a bunch of times ... mostly in setting the parms: I've used both .DefaultValue = something :: and .Equals(something)
protected void grdPCCletters_RowCommand(object sender, GridViewCommandEventArgs e)
{
// for the SP
string strSuppress = "1";
string strRelease = "8";
// get all the variables for the stored procedure call
string strCampaign = grdPCCletters.Rows[int.Parse(e.CommandArgument.ToString())].Cells[3].Text;
//string strUPS = grdPCCletters.Rows[int.Parse(e.CommandArgument.ToString())].Cells[4].Text;
bool boolUPS = Convert.ToBoolean(grdPCCletters.Rows[int.Parse(e.CommandArgument.ToString())].Cells[4].Text);
int intCurrStatus = Convert.ToInt16(grdPCCletters.Rows[int.Parse(e.CommandArgument.ToString())].Cells[8].Text);
Int64 intFileID = Convert.ToInt64( grdPCCletters.Rows[int.Parse(e.CommandArgument.ToString())].Cells[9].Text);
string strFullName = grdPCCletters.Rows[int.Parse(e.CommandArgument.ToString())].Cells[10].Text;
string strEcode = grdPCCletters.Rows[int.Parse(e.CommandArgument.ToString())].Cells[11].Text;
//int intReturnValue; --- GRRR, how to get the returnvalue from the sp??
// sqlAlterStatus.SelectParameters.UpdateValues
// these values apply regardless of the action
sqlAlterStatus.SelectParameters["FILE_ID"].DefaultValue = intFileID.ToString();
sqlAlterStatus.SelectParameters["Campaign_Name"].DefaultValue = strCampaign;
sqlAlterStatus.SelectParameters["UPSCheck"].DefaultValue = Convert.ToInt16(boolUPS).ToString();
sqlAlterStatus.SelectParameters["ECODE"].DefaultValue = strEcode;
sqlAlterStatus.SelectParameters["FULLNAME"].DefaultValue = strFullName;
{
if (e.CommandName.ToString() == "Suppress")
{
//sqlAlterStatus - set parameters
sqlAlterStatus.SelectParameters["ACTION"].DefaultValue = (Convert.ToInt16(strSuppress)).ToString();
// execute SP
sqlAlterStatus.DataBind();
//intReturnValue = sqlAlterStatus.SelectParameters["ReturnValue"].ToString();
}
else if (e.CommandName.ToString() == "Release")
{
//sqlAlterStatus
sqlAlterStatus.SelectParameters["ACTION"].Equals(Convert.ToInt16(strRelease));
sqlAlterStatus.DataBind();
}
}
}