Solved

another way  of structuring the sqlcommand if parameter is an OUTPUT

Posted on 2016-10-05
1
46 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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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