Question

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));
Was it helpful?

Solution

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.

OTHER TIPS

            param.ParameterName = "@isExpired";
            param.Value =chkExpired.Checked; 
            param.DbType = System.Data.DbType.Boolean;
            cmd.Parameters.Add(param);

Just use the value of your checkbox (chkExpired.Checked):

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

you'll want to add the parameter either way, as a boolean :

CmdGetDetails.Parameters.Add(new SqlParameter("@isExpired", chkExpired.Checked));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top