Solved

another way  of structuring the sqlcommand if parameter is an OUTPUT

Posted on 2016-10-05
1
58 Views
Last Modified: 2016-10-07
Here is one way to code a class if a parameter passed is an OUTPUT

1. new SqlParameter("@NewID", SqlDbType.Int) {DbType = DbType.Int32, Direction = ParameterDirection.Output }

however my current code is structured this way...
2. myCommand.Parameters.Add(new sqlParameter("@lastupdated", _lastupdated));

I want to add the output parameter code underneath with the same code style  rather than this  
"new SqlParameter("@NewID", SqlDbType.Int) {DbType = DbType.Int32, Direction = ParameterDirection.Output }"

how will I add the Direction and Parameter definition using that style of coding like #2?
0
Comment
Question by:zachvaldez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 41830121
Hi zachvaldez;

There is no way that I know of to feed the direction parameter as a parameter to the constructor. First create the parameter and supply that to your line 2 as shown below.
' Add the input parameter and set its properties.
Dim parameter As New SqlParameter()
parameter.ParameterName = "@lastupdated"
parameter.SqlDbType = SqlDbType.DateTime
parameter.Direction = ParameterDirection.Input
parameter.Value = _lastupdated

' Add the parameter to the Parameters collection.
myCommand.Parameters.Add(parameter)

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question