Hi
I've got this function that executes a stored procedure. One of the
parameters is an output parameter but for some reason it always returns 0.
Any clues?
Cheers
James
Public Shared Sub StoredProcExecu teNonQuery(ByVa l strSP As String, ByVal
ParamArray aryParams() As SqlParameter)
'connection obj
Dim objConn As SqlConnection
objConn = DBConnect()
'create the command obj
Dim objCMD As New SqlCommand
objCMD.CommandT ext = strSP
objCMD.Connecti on = objConn
objCMD.CommandT imeout = 1440
objCMD.CommandT ype = CommandType.Sto redProcedure
'parameters
Dim Ct As Integer
For Ct = 0 To UBound(aryParam s)
If aryParams(Ct).P arameterName <> "" Then
Dim cmdParam As New SqlParameter
cmdParam.Parame terName = aryParams(Ct).P arameterName
cmdParam.SqlDbT ype = aryParams(Ct).S qlDbType
cmdParam.Direct ion = aryParams(Ct).D irection
cmdParam.Value = aryParams(Ct).V alue
objCMD.Paramete rs.Add(cmdParam )
End If
Next
'create and exec the data reader
Try
objCMD.ExecuteN onQuery()
objConn.Close()
Catch ex As Exception
End Try
End Sub
I call this by
Dim sqlDatasetCode As New SqlParameter("@ code", sCode)
Dim sqlDatasetID As New SqlParameter
sqlDatasetID.Pa rameterName = "@dataset"
sqlDatasetID.Sq lDbType = SqlDbType.Int
sqlDatasetID.Si ze = 4
sqlDatasetID.Di rection = ParameterDirect ion.Output
Database.Stored ProcExecuteNonQ uery("lookup_da taset_by_code", sqlDatasetCode,
sqlDatasetID)
If IsDBNull(sqlDat asetID.Value) = False Then
Return sqlDatasetID.Va lue
Else
Return 0
End If 3 1364
Can you post the stored procedure too?
--
Ben Lucas
Lead Developer
Solien Technology, Inc. www.solien.com
"James Brett" <ja*********@un ified.co.uk> wrote in message
news:u$******** ******@tk2msftn gp13.phx.gbl... Hi
I've got this function that executes a stored procedure. One of the parameters is an output parameter but for some reason it always returns 0.
Any clues?
Cheers James
Public Shared Sub StoredProcExecu teNonQuery(ByVa l strSP As String, ByVal ParamArray aryParams() As SqlParameter)
'connection obj
Dim objConn As SqlConnection
objConn = DBConnect()
'create the command obj
Dim objCMD As New SqlCommand
objCMD.CommandT ext = strSP
objCMD.Connecti on = objConn
objCMD.CommandT imeout = 1440
objCMD.CommandT ype = CommandType.Sto redProcedure
'parameters
Dim Ct As Integer
For Ct = 0 To UBound(aryParam s)
If aryParams(Ct).P arameterName <> "" Then
Dim cmdParam As New SqlParameter
cmdParam.Parame terName = aryParams(Ct).P arameterName
cmdParam.SqlDbT ype = aryParams(Ct).S qlDbType
cmdParam.Direct ion = aryParams(Ct).D irection
cmdParam.Value = aryParams(Ct).V alue
objCMD.Paramete rs.Add(cmdParam )
End If
Next
'create and exec the data reader
Try
objCMD.ExecuteN onQuery()
objConn.Close()
Catch ex As Exception
End Try
End Sub I call this by
Dim sqlDatasetCode As New SqlParameter("@ code", sCode)
Dim sqlDatasetID As New SqlParameter
sqlDatasetID.Pa rameterName = "@dataset"
sqlDatasetID.Sq lDbType = SqlDbType.Int
sqlDatasetID.Si ze = 4
sqlDatasetID.Di rection = ParameterDirect ion.Output
Database.Stored ProcExecuteNonQ uery("lookup_da taset_by_code",
sqlDatasetCode, sqlDatasetID)
If IsDBNull(sqlDat asetID.Value) = False Then
Return sqlDatasetID.Va lue
Else
Return 0
End If
CREATE PROCEDURE [lookup_dataset_ by_code]
@code VARCHAR(16),
@dataset INT OUTPUT
AS
SELECT @dataset = p_dataset
FROM dataset
WHERE code = @code
GO
cheers j
"Ben Lucas" <be*@nospam.sol ien.nospam.com> wrote in message
news:kI******** ************@co mcast.com... Can you post the stored procedure too?
-- Ben Lucas Lead Developer Solien Technology, Inc. www.solien.com
"James Brett" <ja*********@un ified.co.uk> wrote in message news:u$******** ******@tk2msftn gp13.phx.gbl... Hi
I've got this function that executes a stored procedure. One of the parameters is an output parameter but for some reason it always returns
0. Any clues?
Cheers James
Public Shared Sub StoredProcExecu teNonQuery(ByVa l strSP As String, ByVal ParamArray aryParams() As SqlParameter)
'connection obj
Dim objConn As SqlConnection
objConn = DBConnect()
'create the command obj
Dim objCMD As New SqlCommand
objCMD.CommandT ext = strSP
objCMD.Connecti on = objConn
objCMD.CommandT imeout = 1440
objCMD.CommandT ype = CommandType.Sto redProcedure
'parameters
Dim Ct As Integer
For Ct = 0 To UBound(aryParam s)
If aryParams(Ct).P arameterName <> "" Then
Dim cmdParam As New SqlParameter
cmdParam.Parame terName = aryParams(Ct).P arameterName
cmdParam.SqlDbT ype = aryParams(Ct).S qlDbType
cmdParam.Direct ion = aryParams(Ct).D irection
cmdParam.Value = aryParams(Ct).V alue
objCMD.Paramete rs.Add(cmdParam )
End If
Next
'create and exec the data reader
Try
objCMD.ExecuteN onQuery()
objConn.Close()
Catch ex As Exception
End Try
End Sub I call this by
Dim sqlDatasetCode As New SqlParameter("@ code", sCode)
Dim sqlDatasetID As New SqlParameter
sqlDatasetID.Pa rameterName = "@dataset"
sqlDatasetID.Sq lDbType = SqlDbType.Int
sqlDatasetID.Si ze = 4
sqlDatasetID.Di rection = ParameterDirect ion.Output
Database.Stored ProcExecuteNonQ uery("lookup_da taset_by_code", sqlDatasetCode, sqlDatasetID)
If IsDBNull(sqlDat asetID.Value) = False Then
Return sqlDatasetID.Va lue
Else
Return 0
End If
In you procedure StoredProcExecu teNonQuery( ) you are making a copy of the
parameter that you sent in, and you pass the copy to the command object.
Thus, the parameter you are using will not have the data since it is not
used in the execution.
In order for that parameter to have the output value, you would have to use
that specific object. For example: Public Shared Sub StoredProcExecu teNonQuery(ByVa l strSP As String,
ByVal ParamArray aryParams() As SqlParameter)
'connection obj
Dim objConn As SqlConnection
objConn = DBConnect()
'create the command obj
Dim objCMD As New SqlCommand
objCMD.CommandT ext = strSP
objCMD.Connecti on = objConn
objCMD.CommandT imeout = 1440
objCMD.CommandT ype = CommandType.Sto redProcedure
'parameters
Dim Ct As Integer
For Ct = 0 To UBound(aryParam s)
//Note the change here objCMD.Paramete rs.Add(aryParam s(Ct))
Next
'create and exec the data reader
Try
objCMD.ExecuteN onQuery()
objConn.Close()
Catch ex As Exception
End Try
End Sub
--
Ben Lucas
Lead Developer
Solien Technology, Inc. www.solien.com
"James Brett" <ja*********@un ified.co.uk> wrote in message
news:Om******** ******@tk2msftn gp13.phx.gbl... CREATE PROCEDURE [lookup_dataset_ by_code] @code VARCHAR(16), @dataset INT OUTPUT AS
SELECT @dataset = p_dataset FROM dataset WHERE code = @code GO
cheers j
"Ben Lucas" <be*@nospam.sol ien.nospam.com> wrote in message news:kI******** ************@co mcast.com... Can you post the stored procedure too?
-- Ben Lucas Lead Developer Solien Technology, Inc. www.solien.com
"James Brett" <ja*********@un ified.co.uk> wrote in message news:u$******** ******@tk2msftn gp13.phx.gbl... Hi
I've got this function that executes a stored procedure. One of the parameters is an output parameter but for some reason it always
returns 0. Any clues?
Cheers James
Public Shared Sub StoredProcExecu teNonQuery(ByVa l strSP As String,
ByVal ParamArray aryParams() As SqlParameter)
'connection obj
Dim objConn As SqlConnection
objConn = DBConnect()
'create the command obj
Dim objCMD As New SqlCommand
objCMD.CommandT ext = strSP
objCMD.Connecti on = objConn
objCMD.CommandT imeout = 1440
objCMD.CommandT ype = CommandType.Sto redProcedure
'parameters
Dim Ct As Integer
For Ct = 0 To UBound(aryParam s)
If aryParams(Ct).P arameterName <> "" Then
Dim cmdParam As New SqlParameter
cmdParam.Parame terName = aryParams(Ct).P arameterName
cmdParam.SqlDbT ype = aryParams(Ct).S qlDbType
cmdParam.Direct ion = aryParams(Ct).D irection
cmdParam.Value = aryParams(Ct).V alue
objCMD.Paramete rs.Add(cmdParam )
End If
Next
'create and exec the data reader
Try
objCMD.ExecuteN onQuery()
objConn.Close()
Catch ex As Exception
End Try
End Sub I call this by
Dim sqlDatasetCode As New SqlParameter("@ code", sCode)
Dim sqlDatasetID As New SqlParameter
sqlDatasetID.Pa rameterName = "@dataset"
sqlDatasetID.Sq lDbType = SqlDbType.Int
sqlDatasetID.Si ze = 4
sqlDatasetID.Di rection = ParameterDirect ion.Output
Database.Stored ProcExecuteNonQ uery("lookup_da taset_by_code", sqlDatasetCode, sqlDatasetID)
If IsDBNull(sqlDat asetID.Value) = False Then
Return sqlDatasetID.Va lue
Else
Return 0
End If
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bari Allen |
last post by:
I have a Stored procedure in SQL, that works, when tested in SQL, with one
input & several output parameters, as follows:
CREATE PROCEDURE myProcedure
@MyID int
, @First varchar(80) OUTPUT
, @Second varchar(80) OUTPUT
, @Third varchar(80) OUTPUT
, @Amount as numeric(18,0) OUTPUT
etc.
|
by: vivienne.netherwood |
last post by:
I am developing an Access Project front end with a SQL server database.
I have written a stored procedure that returns a record set and also a
value via an output parameter.
The procedure is as follows
CREATE PROCEDURE qslCheckShiftTimes
@Ward NVARCHAR(6),
@Shift NVARCHAR(10),
@Exists TINYINT OUTPUT
AS
|
by: Janaka |
last post by:
Hi this is kind of an ASP.NET/ADO.NET question. I've got a stored procedure
on SQL Server that returns a results set. It also sets 3 output parameters
in a seperate Select statement. When checking this on the database it
returns all the results and output parameters. Now when I set up my
SqlCommand objects parameters I specify 2 input and 3 output parameters. It
executes and returns a SqlDataReader which works fine. However when I go...
|
by: Bari Allen |
last post by:
ASP Classic question:
I have a Stored procedure in SQL, that works, when tested in SQL, with one
input & several output parameters, as follows:
CREATE PROCEDURE myProcedure
@MyID int
, @First varchar(80) OUTPUT
, @Second varchar(80) OUTPUT
, @Third varchar(80) OUTPUT
, @Amount as numeric(18,0) OUTPUT
|
by: juststarter |
last post by:
Hello all,
I am executing a stored procedure (on an SQL Server) using ODBC but i can't
get the output parameter's value on the client. The stored proc has 3
parameters ,2 of them are input and 1 is output. (for shake of simplicity
let's suppose that the proc seems something like
--------------------------------------------------------------------
alter storedProcsName @inputParam1 varchar(20), @inputParam2 varchar(20),
@outputParam...
| |
by: Joe Van Meer |
last post by:
Hi all,
I have an app that currently runs through 3 seperate stored procedures each
returning a count of records. What I would like to do is combine these
calls into one call, however I am having an issue getting the output
parameters' values after execution. Here is a snipit of code that calls one
for simplicity's sake: I think I am close, i was under the impression I
could use the datareader to get at it, but is is always returning ...
|
by: Garth Wells |
last post by:
Using an example in the Jan 2006 release of the Enterprise Library,
I came up with the code shown below to create a DAL method
for returning several columns of a single row. I place the output
parameter values in a comma-separated string, and then split
the string to get the individual values on the calling page. This
approach works, but I can't help but think there is a more
efficient way to accomplish this.
Thanks for any insight you...
|
by: c676228 |
last post by:
Hi everyone,
I wrote a store procedure that fetch one row data in the database based on
the parameter value I entered. After I created the store procedure,
the store procedure code looks like this:
ALTER proc getProductCommScale @product As varchar(30), @TISCommRate As
Decimal(5,2) OUTPUT,
@BrokerCommRate As Decimal(5,2) OUTPUT, @Fee As Decimal(5,2) OUTPUT
As
if RTRIM(@product)='Imed'
Select @TISCommRate=TISComm,...
|
by: John Bailo |
last post by:
This is a my solution to getting an Output parameter from a SqlDataSource.
I have seen a few scant articles but none of them take it all the way to
a solution. Hopefully this will help some poor soul.
Situation: I want to do a lookup using a stored procedure for each
value in a Row within a GridView.
I use a lookup function in my code behind, evaluating the necessary
bound fields. The problem is the SqlDataSource representing...
|
by: gabosom |
last post by:
Hi! I've been breaking my head trying to get the output variables from my Stored Procedure.
This is my SP code
CREATE PROCEDURE GetKitchenOrderDetail(
@idService int,
--outPut Variables
@idUser int OUTPUT,
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |