Wrox Programmer Forums
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP 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 July 14th, 2006, 05:20 PM
Registered User
 
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Null Return value

Hi

I am using following stored procedure
-----------------------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[GetUserControlTemplateCode]
    @product_id int,
    @genmask_code nvarchar(max) output
AS
BEGIN
    SET NOCOUNT ON;

    Select dbo.cp_product.product_type, dbo.cp_genmask.genmask_code
    from dbo.cp_genmask inner join dbo.cp_product
    on dbo.cp_genmask.genmask_product_type=dbo.cp_product .product_type
    where dbo.cp_product.product_id=@product_id

END
--------------------------------
when I execute the above code using

exec GetUserControlTemplateCode 1,'x'

I get correct values for x i.e. output parameter.


My code behind to call stored procedure is as follows

---------------------------------
protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrin gs["sConnectionString2"].ConnectionString);
        SqlCommand Com = con.CreateCommand();
        Com.CommandType = CommandType.StoredProcedure;
        Com.CommandText = "GetUserControlTemplateCode";

        //Create parameter object to provide input
        SqlParameter parInput = Com.Parameters.Add("@product_id", SqlDbType.Int);
        parInput.Direction = ParameterDirection.Input;
        parInput.Value = nProductID;

        // Create parameter to hold output
        SqlParameter parOutput = Com.Parameters.Add("@genmask_code", SqlDbType.NVarChar,300);
        parOutput.Direction = ParameterDirection.Output;

        //Open the connection
        con.Open();
        //Execute command
        try
        {
            Com.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }

        string sTemplateCode = Convert.ToString(parOutput.Value);
        sTemplateCode = sTemplateCode.Replace("ProductID", nProductID.ToString());
        Control myControl = ParseControl(sTemplateCode);
        PlaceHolderForProducts.Controls.Add(myControl);
       con.Close();
    }
-----------------------------------

when I execute the code, i do not get any exception, but the value of output parameter is null.

Can someone please help me to understand whats missing here?

Thanks.
 
Old July 27th, 2006, 02:53 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I do not see where you are assigning a value to your output parameter, this would be why it is retuning a NULL value.

"The one language all programmers understand is profanity."





Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure return value is NULL kshort ASP.NET 2.0 Basics 16 March 14th, 2017 12:45 PM
ASP.NET AJAX: $get and $find return null bmains ASP.NET 3.5 Professionals 0 July 15th, 2008 09:15 AM
Reporting Services - Return Null using '%' gschmidt SQL Server 2000 2 May 26th, 2006 11:05 AM
Null Ignored... Why? SerranoG Access VBA 13 December 28th, 2005 12:41 PM
How to set Not Null constraint to Null Columns arasu Oracle 1 August 22nd, 2005 10:09 AM





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