How to handle an SQL DB Bit value
I have a table that has a column (IsParticipant) that is set as a BIT type that can be NULL, 1 or 0. The intent is to use the NULL to determine if the customer has made a selection, i.e. Yes or No (Radio Buttons on web page).
I have a stored procedure that is used to get the field IsParticipant.
ALTER PROCEDURE [dbo].[X_GetParticipantForXAndY]
@xID uniqueidentifier,
@yID uniqueidentifier,
@IsParticipant bit output
AS
BEGIN
If @xID is null
BEGIN
RaisError('xID must be provided.', 16, 1);
Return 1;
END
If @yID is null
BEGIN
RaisError('yID must be provided.', 16, 1);
Return 1;
END
SET NOCOUNT ON;
SELECT @IsParticipant = DS.IsParticipant
FROM DShows DS
WHERE DS.xID = @xID and DS.yID = @yID;
END
I then have a class method that calls the stored procedure and then I want to use that NULL, 1 or 0 to set the True or False settings for the Yes and No Radio Buttons. If the value is null I want both radio buttons set to false.
sqlParameter = sqlCommand.Parameters.Add(new SqlParameter("@IsParticipant", SqlDbType.Bit));
sqlParameter.Direction = ParameterDirection.Output;
SqlHelper.ExecuteNonQuery("X_GetParticipantForXAndY", sqlCommand);
My initial thought was to have the method be set to return a Boolean.
My issue is, I am having problems returning the null, 1 or 0 back to the web page class -
Boolean isParticipant = Webpg.GetParticipant(xID, yID)
Based on how I setup the return statement, I can either get the null passed or the 1 & 0 but not the three values. What am I doing wrong? I am new this type of environment and it has been years since I have programmed with other OO Language.
I have tried these three return statements:
return Convert.ToBoolean(sqlCommand.Parameters["@IsSHSLogParticipant"].Value.Equals(sqlCommand.Parameters["@IsSHSLogParticipant"].IsNullable));
return Convert.ToBoolean(sqlCommand.Parameters["@IsSHSLogParticipant"].Value);
return Convert.ToBoolean(sqlCommand.Parameters["@IsSHSLogParticipant"]);