使用SqlStorage时,Filehelpers中的ErrorHandling

本文关键字:中的 ErrorHandling Filehelpers SqlStorage 使用 | 更新日期: 2023-09-27 18:08:37

我提供了包含整数类型列的记录,而不是报告错误(如这里所述),在下面的方法中得到InvalidCastException(用于在存储中填充记录):

protected void FillRecordOrder(object rec, object[] fields)
{
    OrdersVerticalBar record = (OrdersVerticalBar) rec;
    record.OrderDate = (DateTime) fields[0];
}

如何处理错误使用SqlStorage在Filehelpers库?

使用SqlStorage时,Filehelpers中的ErrorHandling

字段[0]的内容是什么?你是说它包含一个整数吗?然后你需要把它转换成DateTime。比如:

protected void FillRecordOrder(object rec, object[] fields)
{
    OrdersVerticalBar record = (OrdersVerticalBar) rec;
    if (fields[0] == null)
      record.OrderDate = DateTime.MinValue;
    else if (fields[0] is DateTime)
      record.OrderDate = (DateTime)fields[0];
    else if (fields[0] is int)
    {
      DateTime baseDate = new DateTime(1900, 1, 1);
      DateTime newDate = baseDate.AddDays((int)fields[0]);
      record.OrderDate = newDate;
    }
}