Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

another way  of structuring the sqlcommand if parameter is an OUTPUT

Posted on 2016-10-05
1
Medium Priority
?
70 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
1 Comment
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

972 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