Another Parameter Question

S

Stephen Lynch

I am running a stored procedure via code but need help with the sytax for
the output parameter:

When I run this it works in SQL:


USE DataInput
GO
DECLARE @MyIdent int

EXEC a_spAppendNewContributionID
@CompanyId=1000,
@PayPeriod="8/12/2006",
@PlanYear=2006,
@ContributionDate="08/25/2006",
@ContributionID = @MyIdent OUTPUT

SELECT @MyIdent AS IdentityValue
SELECT * FROM MassPost


Here's part of my code. 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
 
C

Cowboy \(Gregory A. Beamer\)

I find it easiest to use the full constructor than it is to set up
parameters and then configure them. It is also less error prone.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside the box!
*************************************************
 
W

William \(Bill\) Vaughn

Ok a few questions:
1) Why are you using OLE DB? The only (good) reason to use the OleDb
provider is to access JET which does not support OUTPUT parameters.
Sometimes people want to create a single application interface for several
backend databases. IMHO this is an exercise in frustration.
2) What exception are you getting from the code in question?
3) Why are you building the Parameter objects in two steps? The language and
compiler support a number of one-step constructors that work very nicely.


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top