issue with boolean datatype
-
Hi.. I am getting below error while executing this code:last line of code is throwing the error.-"Format exception unhandled by code.String was not recognized as a valid Boolean."
WinnersBLL objperiods = new WinnersBLL();
DataTable dt\_GetCurrentPeriod = new DataTable(); dt\_GetCurrentPeriod = (DataTable)Session\["WinBudget"\]; GridEditableItem insertedItem = e.Item as GridEditableItem; if(Convert.ToBoolean(dt\_GetCurrentPeriod.Rows\[0\]\["IsCurrentPeriod"\].ToString()) == true)
{
some task.
}If "Iscurrentperiod" column in the datatable is null ,its giving the error. how to check for null or false ?
-
Hi.. I am getting below error while executing this code:last line of code is throwing the error.-"Format exception unhandled by code.String was not recognized as a valid Boolean."
WinnersBLL objperiods = new WinnersBLL();
DataTable dt\_GetCurrentPeriod = new DataTable(); dt\_GetCurrentPeriod = (DataTable)Session\["WinBudget"\]; GridEditableItem insertedItem = e.Item as GridEditableItem; if(Convert.ToBoolean(dt\_GetCurrentPeriod.Rows\[0\]\["IsCurrentPeriod"\].ToString()) == true)
{
some task.
}If "Iscurrentperiod" column in the datatable is null ,its giving the error. how to check for null or false ?
bigphish wrote:
Convert.ToBoolean(dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"].ToString())
Error is raised if the converted string value of
dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"]
is not a 'true
' or 'false
'. Anything other then them would raise that error. Try something like this:if(dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"] != null)
{
if(Convert.ToBoolean(dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"].ToString()) == true)
{
//some task.
}
} -
bigphish wrote:
Convert.ToBoolean(dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"].ToString())
Error is raised if the converted string value of
dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"]
is not a 'true
' or 'false
'. Anything other then them would raise that error. Try something like this:if(dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"] != null)
{
if(Convert.ToBoolean(dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"].ToString()) == true)
{
//some task.
}
} -
hi.., if,
dt_GetCurrentPeriod.Rows[0]["IsCurrentPeriod"]
is 'false' also its giving error..It is working fine only if "IsCurrentPeriod" is true.. If the field is null its taking as false and giving error.I made this as nullable column.
-
Hi.. I am getting below error while executing this code:last line of code is throwing the error.-"Format exception unhandled by code.String was not recognized as a valid Boolean."
WinnersBLL objperiods = new WinnersBLL();
DataTable dt\_GetCurrentPeriod = new DataTable(); dt\_GetCurrentPeriod = (DataTable)Session\["WinBudget"\]; GridEditableItem insertedItem = e.Item as GridEditableItem; if(Convert.ToBoolean(dt\_GetCurrentPeriod.Rows\[0\]\["IsCurrentPeriod"\].ToString()) == true)
{
some task.
}If "Iscurrentperiod" column in the datatable is null ,its giving the error. how to check for null or false ?