The stored procedure returns a Boolean value and C # related processing,
Some time ago there was a problem where Boolean values were used between databases and programs.
For example, in SQL, do you want to determine whether the records are saved? Generally, you write:
DECLARE @ IsExists BIT = 0IF EXISTS (select top 1 1 FROM [dbo]. [SixSResponsiblePerson] WHERE [SixS_nbr] = @ SixS_nbr AND [UsersId] = @ UsersId) SET @ IsExists = 1 SELECT @ IsExistsView Code
Or you can follow the habits of Insus. NET:
Select case when exists (select top 1 1 FROM [dbo]. [SixSResponsiblePerson] WHERE [SixS_nbr] = @ SixS_nbr AND [UsersId] = @ UsersId) then cast (1 as bit) else cast (0 as bit) ENDView Code
In the database return value, the stored procedure only returns the data type bits, "1" and "0 ". Now we apply this stored procedure in the C # program:
In C #, when the data is converted to the bool value, only "0" is converted to false, and other values are converted to true.
In general, there is no problem with the above situation,
Let's take a look at the database design:
This field can be null, meaning three values are stored, true, false, and null.
When writing a stored procedure, you need to pay attention to it. We only need to judge if NULL is NULL or if 0 is false. Other judgments are true.
OK, the above stored procedure is also suitable for another situation, such as using tinyint.