S
Steven
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
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