title: Return an output parameter from SQL Server via a stored procedure and c#
body: <p>I am having a devil of a time getting an output value from SQL Server.</p>
  
  <p>Here is my stored procedure:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[Insert_UnknownCustomer_Quote_Document]
  -- Add the parameters for the stored procedure here
  @NewDocumentFileName nvarchar(100),
  @NewDocumentWordCount int,
  @NewQuoteAmount money,
  @NewQuoteNumber int OUTPUT = 0
  
  AS
  
  DECLARE @Today datetime
  SELECT @Today = GETDATE()
  
  BEGIN TRANSACTION
  BEGIN TRY
  
  BEGIN
  -- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements.
  SET NOCOUNT ON;
  
  
  -- Insert statements for procedure here
  INSERT INTO dbo.Customers(DateAdded)
  VALUES (@Today)
  
  INSERT INTO dbo.Quotes(CustomerID, QuoteAmount, QuoteDate)
  VALUES (@@IDENTITY, @NewQuoteAmount, @Today)
  
  SELECT @NewQuoteNumber = @@IDENTITY
  INSERT INTO dbo.DocumentFiles(QuoteNumber, DocumentFileName, DocumentFileWordCount)
  VALUES (@NewQuoteNumber, @NewDocumentFileName, @NewDocumentWordCount)
  
  -- Return quote number
  RETURN @NewQuoteNumber
  
  END
  COMMIT TRANSACTION
  END TRY
  
  BEGIN CATCH
  ROLLBACK TRANSACTION
  PRINT 'Transaction rolled back.'
  END CATCH
  </code></pre>
  
  <p>And here is my C#:</p>
  
  <pre><code>SqlParameter returnQuoteNumber = new SqlParameter("@NewQuoteNumber", SqlDbType.Int);
          returnQuoteNumber.Direction = ParameterDirection.ReturnValue;
          newSQLCommand.Parameters.Add(returnQuoteNumber);
  </code></pre>
  
  <p>Here is the error I am receiving now:</p>
  
  <pre><code>Procedure or function 'Insert_UnknownCustomer_Quote_Document' expects parameter '@NewQuoteNumber', which was not supplied.
  </code></pre>
  
  <p>I have tried taking @NewQuoteNumber out of the beginning and placing it after the AS with a DECLARE but that produces an error, too.</p>