user3135597 user3135597 - 7 months ago 20
SQL Question

How to Pass Bool (BIT) parameter to SQL server?

I have a stored procedure in sql which has a bit parameter.I need to pass the parameter value from c#.Can Someone help me how to do it. I passed true/false value to the bit parameter but it is not working.

CREATE PROCEDURE checkbit
@id varchar(10),
@IsDeleted bit
AS
BEGIN

IF(@IsDeleted = 1)
BEGIN
DELETE FROM tablename WHERE ID = @id

RETURN
END
END


My C# code

Im using entity framework.Checking for bit value here.

bool chk;
if(val==1)
chk=true;
else
chk=false;
context.checkbit(id,chk)

Answer

You can just use 0 or 1 for the BIT field

  • 1 for TRUE
  • 0 for FALSE

context.checkbit(id,val);// ? 1 : 0;