Help with Output Parameter Statement



All:

I am running a stored procedure via code but need help with the sytax for
the output parameter as mine is wrong, Sorry, but I am just learning.
Here's my incorrect section, more is listed below:

OleDbParameter parameterContributionID = new
OleDbParameter("@ContributionID", OleDbType.Integer, 4);
parameterContributionID.Direction =
ParameterDirection.Output



Here's my Procedure:

******************************************************************
USE DataInput

GO

CREATE PROC a_spAppendNewContributionID

@CompanyId int,

@PayPeriod datetime,

@PlanYear int,

@ContributionDate datetime,

@ContributionId int OUTPUT

AS

/* Create the new record */

INSERT INTO Contributions

VALUES

(

@CompanyId,

@PayPeriod,

@PlanYear,

@ContributionDate

)

/* Move the identity value from the newly inserted record into

our output variable */

SELECT @ContributionId = @@IDENTITY



INSERT INTO MassPost

(ContributionId,EmployeeUID,FullName,Post)



SELECT Contributions.ContributionId,Employees.EmployeeUID,Employees.Last +',
'+ Employees.First +' '+ ISNULL( Employees.Middle,'' ) AS 'FullName','0'

FROM Contributions, Employees

WHERE ContributionId = @@IDENTITY AND

Employees.CompanyId=@CompanyId And

Employees.AllowContributions = 1

ORDER BY FullName

***************************************************************

Here's part of my code in asp. The @contributionID section is where I am
stuck, how do I declare the output parameter?

// Add Parameters to SPROC

OleDbParameter parameterCompanyId = new
OleDbParameter("@CompanyId", OleDbType.Integer, 4);
parameterCompanyId.Value = SystemUtils.GetUserID();
myCommand.Parameters.Add(parameterCompanyId);

OleDbParameter parameterPayPeriod = new
OleDbParameter("@PayPeriod", OleDbType.Date, 8);
parameterPayPeriod.Value = this.PayPeriod2.Text;
myCommand.Parameters.Add(parameterPayPeriod);

OleDbParameter parameterPlanYear = new
OleDbParameter("@PlanYear", OleDbType.Integer, 4);
parameterPlanYear.Value = this.PlanYear2.Text;
myCommand.Parameters.Add(parameterPlanYear);

OleDbParameter parameterContributionDate = new
OleDbParameter("@ContributionDate", OleDbType.Date, 8);
parameterContributionDate.Value =
this.ContributionDate2.Text;
myCommand.Parameters.Add(parameterContributionDate);

//Line that does not work

OleDbParameter parameterContributionID = new
OleDbParameter("@ContributionID", OleDbType.Integer, 4);
parameterContributionID.Direction =
ParameterDirection.Output

Thanks in advance

Steve



.



Relevant Pages

  • Re: Help with Output Parameter Statement
    ... In your stored proc, you should store the @@Identity in a variable and use ... the output parameter as mine is wrong, Sorry, but I am just learning. ... OleDbParameter parameterContributionID = new ... @ContributionId int OUTPUT ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Help with Output Parameter Statement
    ... // Create Instance of Connection and Command Object ... OleDbParameter parameterContributionID = new ... OUTPUT parameter values. ... @ContributionId int OUTPUT ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Help with Output Parameter Statement
    ... // Create Instance of Connection and Command Object ... OleDbParameter parameterContributionID = new ... OUTPUT parameter values. ... @ContributionId int OUTPUT ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Help with Output Parameter Statement
    ... in ADO.NET OUTPUT parameters are not available until all of the rows ... If using SQL Server you should use Scope_Identity instead of @@Identity. ... OleDbParameter parameterContributionID = new ... @ContributionId int OUTPUT ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Output Parameter Help
    ... @ContributionID = @MyIdent OUTPUT ... output parameter values. ... but this is a classic ADO newsgroup. ...
    (microsoft.public.data.ado)