它说:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
答案 0 :(得分:1)
你不能使用拆箱将字符串类型拆箱到类型bool我怀疑一个是另一个的子类,反之亦然。你必须使用预定义的功能。
Convert.ToBoolean(reader["Complimentary"].ToString());
答案 1 :(得分:1)
试试这个:
object value = reader["Complimentary"];
if(value != null && value != DBNull.Value)
{
CbIsComplimentary.Checked = (bool)value;
}
else
{
//Optionally handle null value, e.g.:
//CbIsComplimentary.Checked = false;
}