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)  
                IF your using Ado.net then try with below hope it will work.
SqlParameter param = new SqlParameter();
             param.ParameterName = "@Isstatus";
             param.Value = Isstatus;
             param.DbType = System.Data.DbType.Boolean
             cmd.Parameters.Add(param);
Entity Framework
if your sp return true or false then below you can use other wise you need to try with void.
using System.Data.Entity.Infrastructure;
using System.Data.Objects;
    public virtual bool Deletecustomer(int id ,bool IsDeleted )
    {
        return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<bool>("EXEC checkbit({0},{1})", id,IsDeleted ).SingleOrDefault();
    }
                        You can just use 0 or 1 for the BIT field
1 for TRUE
0 for FALSE
context.checkbit(id,val);// ? 1 : 0;
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With