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));
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));
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.
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));
© 2022 - 2024 — McMap. All rights reserved.
isExpired
looked like boolean field, represented asbit
in SQL Server. Are you sure you have anint
field – Blocking