How to pass correct object value in SqlParameter for datatype bit?

JoJo picture JoJo · May 2, 2014 · Viewed 9.6k times · Source

I am trying to pass a bit value only if needed (is checked).

How do I do this correctly? I am not getting a change in my dataset. SQL Server 2008.

if (chkExpired.Checked)
    CmdGetDetails.Parameters.Add(new SqlParameter("@isExpired", 1));

Answer

Parimal Raj picture Parimal Raj · May 2, 2014

bit refers to Boolean

so you would pass a boolean value in parameter's value

Ex :

CmdGetDetails.Parameters.AddWithValue("isExpired", chkExpired.Checked); 

There is no addtional need to use a if block.