HighTechTalks DotNet Forums  

Another Parameter Question

Dotnet Framework (ADO.net) microsoft.public.dotnet.framework.adonet


Discuss Another Parameter Question in the Dotnet Framework (ADO.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Stephen Lynch
 
Posts: n/a

Default Another Parameter Question - 09-04-2006 , 09:53 AM






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



Reply With Quote
  #2  
Old   
Cowboy \(Gregory A. Beamer\)
 
Posts: n/a

Default Re: Another Parameter Question - 09-04-2006 , 12:53 PM






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!
*************************************************
"Stephen Lynch" <raider1raider (AT) yahoo (DOT) com> wrote

Quote:
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




Reply With Quote
  #3  
Old   
William \(Bill\) Vaughn
 
Posts: n/a

Default Re: Another Parameter Question - 09-04-2006 , 12:59 PM



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.
__________________________________

"Stephen Lynch" <raider1raider (AT) yahoo (DOT) com> wrote

Quote:
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




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.