Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6051345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:48:41+00:00 2026-05-23T07:48:41+00:00

I am passing a value to a parameter in a Stored Procedure and also

  • 0

I am passing a value to a parameter in a Stored Procedure and also declaring it’s direction as ParameterDirection.InputOutput. In the Stored Procedure, the parameter is also declared as an OUTPUT parameter and the value being returned from the Stored Procedure is correct. I know this because I have tested executing the Stored Procedure on its own and using PRINT to display different values throughout the procedure. Also, the final part of the Stored Procedure inserts a record into the database using the value that I am expecting to be returned and that is appearing as expected. However, when I attempt to retrieve the value from the parameter after the SqlCommand has been executed, the value is still the previous value that I passed to the Stored Procedure. I have done this before and I am sure I’ve done it no differently. Here’s a part of my command:

Dim cmd As New SqlCommand("StoredProcedure", Conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@FileName", SqlDbType.NVarChar).Value = ImageFileNameNoExt
cmd.Parameters("@FileName").Direction = ParameterDirection.InputOutput
cmd.ExecuteNonQuery()
ImageFileName = cmd.Parameters("@FileName").Value

Here, I am expecting ImageFileName to be the value of the @FileName parameter, returned from the Stored Procedure. However, it’s still the same value as ImageFileNameNoExt which was passed to the procedure in the first place.

Can someone please tell me what I’m doing wrong? Thanks.

EDIT

ALTER PROCEDURE [dbo].[sp_ContentPages_Images_Update]
    @PageID int
    ,@FileName nvarchar(100) OUTPUT
    ,@Ext nvarchar(100)
AS
BEGIN
    SET NOCOUNT ON;

    --As the FileName is a unique key, ensure that the value being entered into the database will be unique.
    --If its not, then we can generate a new one
    SET @FileName = REPLACE(@FileName, ' ', '-')
    DECLARE @i int
            ,@FileNameCheck nvarchar(200)
    SET @i = 2
    SET @FileNameCheck = @FileName + @Ext
    WHILE (SELECT COUNT(*)
        FROM [ContentPages_Images]
        WHERE [FileName]=@FileNameCheck
        AND (@PageID IS NULL OR NOT @PageID=ID)
        ) > 0
    BEGIN
        SET @FileNameCheck = @FileName + '-' + CAST(@i as nvarchar(3)) + @Ext
        SET @i = @i + 1
    END

    SET @FileName = @FileNameCheck

    --Get new layout value
    DECLARE @Layout int
    SET @Layout = 1
    IF (SELECT COUNT(*) FROM [ContentPages_Images] WHERE PageID=@PageID) > 0
    BEGIN
        SET @Layout = (SELECT MAX(Layout) FROM [ContentPages_Images] WHERE PageID=@PageID) + 1
    END

    INSERT INTO [ContentPages_Images]
    (PageID, [FileName], [Layout])
    VALUES
    (@PageID, @FileName, @Layout)

END
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:48:42+00:00Added an answer on May 23, 2026 at 7:48 am

    This is most likely because you haven’t specified a size for the parameter. Try changing your code to include the parameter’s size like the following:

    cmd.Parameters.Add("@FileName", SqlDbType.NVarChar, 100).Value = ImageFileNameNoExt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am passing a parameter into a stored procedure: param = CreateInParameter(Result, DbType.Decimal); param.Value
I am having troubles passing multiple parameter to the crystal report stored procedure. I
I have a CLR stored procedure that takes a value from an arbitrary column
I am passing one parameter/object to the function RefValTest(object oIn) by the value but
I'm passing query string parameter to .aspx page with 'Ñ' character in value. But
I'm trying to glue together two web services by passing a value from one
I'm trying to call a parameterized stored procedure from SQL Server 2005 in my
I have a stored procedure which I cann from my C# code. I am
I have a problem parsing a stored procedure parameter in the form: declare @S
In my stored procedure I am passing a filter (using WHERE Column IN clause)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.