E
Eugene Banks
I am using a stored procedure on SQL server to test for a few
conditions, setting a BIT depending on the result of each test. Each
BIT parameter is defined as an output param in the stored procedure and
set to 0 by default. From my code, I define each parameter, add them to
the SqlCommand object, and then ExecuteNonQuery(). When I check the
output paramaters on my SqlCommand object, they now have a value of
DBNull, even though they are initialized to 0 by the procedure. When I
run the stored procedure from a query window, the sp behaves as
expected. Please help!
Stored procedure snippit
--------------------------------------
@ParticipantExists BIT = 0 OUTPUT
-- Check for valid Participant
IF EXISTS (SELECT p.ind_id
FROM Participant p, Employer e
WHERE e.alias = @Co_Code
AND e.employer_id = p.employer_id
AND p.external_id = @Employee_Identifier)
BEGIN
SET @IndividualID = (SELECT p.ind_id
FROM Participant p, Employer e
WHERE e.alias = @Co_Code
AND e.employer_id = p.employer_id
AND p.external_id = @Employee_Identifier)
SET @ParticipantExists = 1
END
C# Code snippit
---------------------------------------
cmd = new SqlCommand("usp_SelectParticipantVerification", conn, tran);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter parm = new SqlParameter("@ParticipantExists", SqlDbType.Bit);
parm.Direction = ParameterDirection.Output;
cmd.Parameters.Add(parm);
cmd.ExecuteNonQuery();
cmd.Parameters["@ParticipantExists"].Value is now DBNull. Any ideas?
Thanks!
conditions, setting a BIT depending on the result of each test. Each
BIT parameter is defined as an output param in the stored procedure and
set to 0 by default. From my code, I define each parameter, add them to
the SqlCommand object, and then ExecuteNonQuery(). When I check the
output paramaters on my SqlCommand object, they now have a value of
DBNull, even though they are initialized to 0 by the procedure. When I
run the stored procedure from a query window, the sp behaves as
expected. Please help!
Stored procedure snippit
--------------------------------------
@ParticipantExists BIT = 0 OUTPUT
-- Check for valid Participant
IF EXISTS (SELECT p.ind_id
FROM Participant p, Employer e
WHERE e.alias = @Co_Code
AND e.employer_id = p.employer_id
AND p.external_id = @Employee_Identifier)
BEGIN
SET @IndividualID = (SELECT p.ind_id
FROM Participant p, Employer e
WHERE e.alias = @Co_Code
AND e.employer_id = p.employer_id
AND p.external_id = @Employee_Identifier)
SET @ParticipantExists = 1
END
C# Code snippit
---------------------------------------
cmd = new SqlCommand("usp_SelectParticipantVerification", conn, tran);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter parm = new SqlParameter("@ParticipantExists", SqlDbType.Bit);
parm.Direction = ParameterDirection.Output;
cmd.Parameters.Add(parm);
cmd.ExecuteNonQuery();
cmd.Parameters["@ParticipantExists"].Value is now DBNull. Any ideas?
Thanks!