我正在尝试将数据保存在Access数据库文件中。
类型' System.InvalidCastException'的例外情况发生在 myapp.exe但未在用户代码中处理
其他信息:无法从a转换参数值 SqlBoolean为布尔值。
内部异常:"对象必须实现IConvertible。
我无法找到对此例外负责的准确代码点。
我应该在哪里找到原因?
DBNullValue.cs
public class DBNullValue
{
public static Object GetNullValue(DbType dataType)
{
Object returnValue;
switch (dataType)
{
case DbType.AnsiString:
case DbType.AnsiStringFixedLength:
case DbType.String:
case DbType.StringFixedLength:
returnValue = SqlString.Null;
break;
case DbType.Double:
returnValue = SqlDouble.Null;
break;
case DbType.Decimal:
case DbType.VarNumeric:
returnValue = SqlDecimal.Null;
break;
case DbType.Single:
returnValue = SqlSingle.Null;
break;
case DbType.Int16:
returnValue = SqlInt16.Null;
break;
case DbType.Int32:
returnValue = SqlInt32.Null;
break;
case DbType.Int64:
returnValue = SqlInt64.Null;
break;
case DbType.UInt16:
returnValue = SqlInt32.Null;
break;
case DbType.UInt32:
returnValue = SqlInt64.Null;
break;
case DbType.UInt64:
returnValue = SqlInt64.Null;
break;
case DbType.Byte:
case DbType.SByte:
returnValue = SqlByte.Null;
break;
case DbType.Boolean:
returnValue = SqlBoolean.Null;
break;
case DbType.DateTime:
case DbType.Date:
case DbType.DateTime2:
case DbType.DateTimeOffset:
case DbType.Time:
returnValue = SqlDateTime.Null;
break;
case DbType.Binary:
case DbType.Object:
default:
returnValue = DBNull.Value;
break;
}
return returnValue;
}
}