I'm calling a stored procedure which has an output parameter of type int.
Once the stored procedure is executed, I want to check the value of the
parameter in case it is null. However, when the a null value is returned I
don't seem to be able to detect it.
Any help would be greatly appreciated.
C# code is as follows:
SqlCommand cmd = new SqlCommand("sp_GetApplicationID", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = cmd.Parameters.Add("@iApplicationID",
SqlDbType.Int);
param.Direction = ParameterDirection.Output;
param = cmd.Parameters.Add("@vcApplicationConstName",
SqlDbType.VarChar);
param.Value = sAppConstName;
if (conn.State == ConnectionState.Closed)
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
// check for null here
if (cmd.Parameters["@iApplicationID"].Value != null){
iID = (int)cmd.Parameters["@iApplicationID"].Value;
}
else{
throw new ApplicationException("Unable to retrieve Application ID for
application: " + sAppConstName);
}
Stored Procedure (for test purposes):
CREATE PROCEDURE [dbo].[sp_BSQ_GetApplicationID]
@vcApplicationConstName varchar(50),
@iApplicationID int OUTPUT
AS
SET @iApplicationID = null
GO
Thanks in advance for your help.
Steven 4 19652
Hello
Compare with DBNull.Value instead of null.
if (cmd.Parameters["@iApplicationID"].Value != DBNull.Value)
{
.....
}
Best regards,
Sherif
"Steven" <st************@virgin.net> wrote in message
news:bo*******************@news.demon.co.uk... I'm calling a stored procedure which has an output parameter of type int. Once the stored procedure is executed, I want to check the value of the parameter in case it is null. However, when the a null value is returned I don't seem to be able to detect it.
Any help would be greatly appreciated.
C# code is as follows:
SqlCommand cmd = new SqlCommand("sp_GetApplicationID", conn); cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = cmd.Parameters.Add("@iApplicationID", SqlDbType.Int); param.Direction = ParameterDirection.Output;
param = cmd.Parameters.Add("@vcApplicationConstName", SqlDbType.VarChar); param.Value = sAppConstName;
if (conn.State == ConnectionState.Closed) conn.Open();
cmd.ExecuteNonQuery(); conn.Close();
// check for null here if (cmd.Parameters["@iApplicationID"].Value != null){ iID = (int)cmd.Parameters["@iApplicationID"].Value; } else{ throw new ApplicationException("Unable to retrieve Application ID for application: " + sAppConstName); }
Stored Procedure (for test purposes):
CREATE PROCEDURE [dbo].[sp_BSQ_GetApplicationID]
@vcApplicationConstName varchar(50), @iApplicationID int OUTPUT
AS
SET @iApplicationID = null
GO
Thanks in advance for your help.
Steven
Steven wrote: I'm calling a stored procedure which has an output parameter of type int. Once the stored procedure is executed, I want to check the value of the parameter in case it is null. However, when the a null value is returned I don't seem to be able to detect it.
Any help would be greatly appreciated.
C# code is as follows:
SqlCommand cmd = new SqlCommand("sp_GetApplicationID", conn); cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = cmd.Parameters.Add("@iApplicationID", SqlDbType.Int); param.Direction = ParameterDirection.Output;
param = cmd.Parameters.Add("@vcApplicationConstName", SqlDbType.VarChar); param.Value = sAppConstName;
if (conn.State == ConnectionState.Closed) conn.Open();
cmd.ExecuteNonQuery(); conn.Close();
// check for null here if (cmd.Parameters["@iApplicationID"].Value != null){ iID = (int)cmd.Parameters["@iApplicationID"].Value; } else{ throw new ApplicationException("Unable to retrieve Application ID for application: " + sAppConstName); }
Stored Procedure (for test purposes):
CREATE PROCEDURE [dbo].[sp_BSQ_GetApplicationID]
@vcApplicationConstName varchar(50), @iApplicationID int OUTPUT
AS
SET @iApplicationID = null
GO
Thanks in advance for your help.
Steven
MSDN says:
When sending a null parameter value to the server, the user must specify
DBNull, not null. The null value in the system is an empty object that
has no value. DBNull is used to represent null values
So try
cmd.Parameters["@iApplicationID"].Value != DBNull.Value
Dmitry
"NULLl" is a valid value and it's not the same as "null" - the literal that
represents a null reference.
Here is some info on DBNull class. http://msdn.microsoft.com/library/de...ClassTopic.asp
"Wilford Munley" <tr****@tinkertoys.net> wrote in message
news:s5********************@adelphia.com... "Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl... Hello
Compare with DBNull.Value instead of null.
if (cmd.Parameters["@iApplicationID"].Value != DBNull.Value) { .... }
Best regards, Sherif
"Steven" <st************@virgin.net> wrote in message news:bo*******************@news.demon.co.uk... I'm calling a stored procedure which has an output parameter of type
int. Once the stored procedure is executed, I want to check the value of
the parameter in case it is null. However, when the a null value is
returned I don't seem to be able to detect it.
Any help would be greatly appreciated.
C# code is as follows:
SqlCommand cmd = new SqlCommand("sp_GetApplicationID", conn); cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = cmd.Parameters.Add("@iApplicationID", SqlDbType.Int); param.Direction = ParameterDirection.Output;
param = cmd.Parameters.Add("@vcApplicationConstName", SqlDbType.VarChar); param.Value = sAppConstName;
if (conn.State == ConnectionState.Closed) conn.Open();
cmd.ExecuteNonQuery(); conn.Close();
// check for null here if (cmd.Parameters["@iApplicationID"].Value != null){ iID = (int)cmd.Parameters["@iApplicationID"].Value; } else{ throw new ApplicationException("Unable to retrieve Application ID
for application: " + sAppConstName); }
Stored Procedure (for test purposes):
CREATE PROCEDURE [dbo].[sp_BSQ_GetApplicationID]
@vcApplicationConstName varchar(50), @iApplicationID int OUTPUT
AS
SET @iApplicationID = null
GO
Thanks in advance for your help.
Steven
Why are DBNull and null different? Aren't they the same thing?
Wilford This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JC |
last post by:
Can someone post a working stored procedure with output variable that
works on northwind db or explain to me what I am missing. I've tried
ever tying but it always returns @outvariable parameter...
|
by: Steven |
last post by:
I'm calling a stored procedure which has an output parameter of type int.
Once the stored procedure is executed, I want to check the value of the
parameter in case it is null. However, when the a...
|
by: Bala |
last post by:
Hi,
This is my stored procured. i try to pass the parametre like this. i am
getting error.
any one please tell me how to pass the parameter?
vb code:
..Connection = New...
|
by: Mr Not So Know It All |
last post by:
im new to SQL Server and ASP.Net. Here's my problem. I have this SQL
Server stored procedure with an input parameter and output parameter
CREATE PROCEDURE .
@in_rc varchar(8)
@out_eList...
|
by: nikolacace |
last post by:
Hi,
I have a stored procedure (the code is below) that I use to retrieve
one value from my database. I tested the code in Query Analyzer, and it
works (I get the value I was looking for). However,...
| |
by: CK |
last post by:
I want the procedure to check for the existence of a paramter and if it is
there, it will process these instructions, otherwise it will process these
instructions. Any ideas? Thanks for your...
|
by: IamtheEvster |
last post by:
Hi All,
I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am
unable to call a MySQL stored procedure that returns output parameters
using mysql, mysqli, or PDO. I'm having a...
|
by: ashtek |
last post by:
Hi,
I have a generic function that executes a stored procedure & returns a
data table.
Code:
===
public static DataTable ExecuteStoredProcedure(string
strProc,SqlParameter paramArray)
{...
|
by: Jeff |
last post by:
Hey
..NET 2.0
I have a stored procedure which calculates a value and return that value.
I'm wondering if I should use ExecuteNonQuery, ExecuteScalar or
ExecuteReader on this stored...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
|
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...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |