Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Ho to Get output parameter value of SPHo to Get output parameter value of SP
Previous
 
Next
New Post
11/25/2008 12:42 AM
 

Hi,

I am not getting the value from my DNN code when executing SP.
Here is my code:

        public override int UploadInfoIconFile(int PortalId, int TabModuleId, int ConfiguratorColumnId, string FileName, string Extension, int Size, string ContentType, byte[] Content)
        {
            SqlParameter @FileId = new SqlParameter();

            int _returnFileId = 0;
            int _newFileId = 0;

            @FileId.Direction = ParameterDirection.Output;
            @FileId.ParameterName = "@FileID";
            @FileId.DbType = DbType.Int16;

            IDataReader iReader = (IDataReader)SqlHelper.ExecuteReader(ConnectionString, "PR_CON_InformationIconFileSave", PortalId, TabModuleId,  ConfiguratorColumnId, FileName, Extension, Size, ContentType, Content, @FileId);

            _newFileId = (int)(@FileId.Value);

            return _newFileId;
        }

When using @FileID.Value it always return "null". Please help me.

Thanks & Regards,
Deepak Khopade

 
New Post
1/8/2009 10:20 AM
 

// Create a new Connection and SqlDataAdapter

            SqlConnection myConnection = new SqlConnection("server=(local)\\SQLExpress;Integrated Security=SSPI;database=northwind");

            // Create stored procedure with out parameter
            try
            {
                SqlCommand CreateProcCommand = new SqlCommand("CREATE PROCEDURE GetCompanyName  @CustomerId nchar(5), @CompanyName nchar(40) out as select @CompanyName = CompanyName from Customers where CustomerId = @CustomerId",myConnection);
                SqlCommand DropProcCommand = new SqlCommand("IF EXISTS (SELECT name FROM sysobjects WHERE name = 'GetCompanyName' AND type = 'P') DROP PROCEDURE GetCompanyName", myConnection);

                myConnection.Open();
                DropProcCommand.ExecuteNonQuery();   // remove procedure if it exists
                CreateProcCommand.ExecuteNonQuery(); // create procedure

                SqlCommand myCommand = new SqlCommand("GetCompanyName", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;

                // Fill the parameters collection based upon stored procedure.
                SqlParameter workParam = null;

                workParam = myCommand.Parameters.Add("@CustomerID", SqlDbType.NChar, 5);
                // ParameterDirection.Input is the default for the Direction property. Thus the following line is not
                // needed here. To set the Direction property to its default value, use the following line.
                // workParam.Direction = ParameterDirection.Input;

                workParam = myCommand.Parameters.Add("@CompanyName", SqlDbType.NChar, 40);
                workParam.Direction = ParameterDirection.Output;

                myCommand.Parameters["@CustomerID"].Value = "ALFKI";

                myCommand.ExecuteNonQuery();
                MsgString = "CompanyName = " + myCommand.Parameters["@CompanyName"].Value.ToString();
            }
            catch(Exception e)
            {
                MsgString = e.ToString();
            }
            finally
            {
                myConnection.Close();
            }


Eric Garza
EGI Consulting
Dallas, TX
(972) 767-5930
View my profile on LinkedIn

Are you looking for DotNetNuke ModulesDotNetNuke Skins or DotNetNuke Support?

 
New Post
1/9/2009 11:12 AM
 

Im a little confused what u are doing..  You are trying to use a Datareader to get an OUTPUT parameter from an SP?

You should post the the SP code as well since that makes a big difference.

SQLHelper is very picky with it's method overloads.  If you accidentally pick the wrong one it will not return the output parameter.

Try SQLHelper.ExecuteNonQuery()

 

 
New Post
1/9/2009 11:20 AM
 

public override int SaveDataAndGetNewID(int SomeInputData)
        {
            try
            {
                string SPName = "SaveDataAndReturnID";
                SqlParameter SomeInputDataParam= new SqlParameter("@SomeInputData", SqlDbType.Int);
                SomeInputDataParam.Value = SomeInputData;
                SqlParameter NewIDParam = new SqlParameter("@NewID", SqlDbType.Int);
                NewIDParam.Direction = ParameterDirection.Output;

                SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, DatabaseOwner + ObjectQualifier + SPName, formUserIDParam, iAppsUserIDParam);

                return (int)NewIDParam.Value;

            }
            catch (Exception ex)
            {

                throw ex;
            }

        }

 
New Post
1/10/2009 1:07 AM
 

I tried with ExecuteReader, ExecuteNonQuery but still i was getting the -1 or 0 for the Output paramter of SP

Anyways,

I found the following way to get the value:

From My SP I have written Select statement to get the newly created row's Unique ID (PK)

SELECT InformationIconFileID = SCOPE_IDENTITY ()
FROM [dbo].[TB_CON_InformationIconFile] iif
WHERE iif.[PortalID] = @PortalID
AND iif.[TabModuleID] = @TabModuleIDAND iif.[ConfiguratorColumnID] = @ConfiguratorColumnID
AND iif.[FileName] = @FileName

this returns one recordset from SP which I am fetching using SqlDataReader. And returns the single column and single row record. Means only one cell

And from SqlDataProvider I have written this simple code:

        public override int UploadInfoIconFile(int PortalId, int TabModuleId, int ConfiguratorColumnId, string FileName, string Extension, int Size, string ContentType, byte[] Content)
        {
            int _returnFileId = 0;

            SqlParameter FileId = new SqlParameter("@FileID", SqlDbType.Int);
            FileId.Direction = ParameterDirection.Output;

            SqlDataReader myReader = SqlHelper.ExecuteReader(ConnectionStringConfig, "PR_CON_InformationIconFileSave", new object[] { PortalId, TabModuleId, ConfiguratorColumnId, FileName, Extension, Size, ContentType, Content, FileId });

            while (myReader.Read())
            {
                _returnFileId = Convert.ToInt32(myReader.GetValue(0));
            }

            return _returnFileId;
        }

That's it :)

And now my code is working fine.

Anyways,

If you feel this wrong or not very optimized  please let me know.

Thanks all for your replies,

Deepak Khopade

 

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Ho to Get output parameter value of SPHo to Get output parameter value of SP


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out