Petapoco更新日期时间错误

时间:2013-02-03 19:06:05

标签: c# datetime petapoco

我尝试使用Petapoco更新一些日期时间字段,但更新总是失败,所以我查找了我的SQL分析器并找到了以下执行语句。

    exec sp_executesql N'UPDATE [db_Product] SET [aName] = @0, [aDesc] = @1, [EmpID] = @2, [UPCCode] = @3, [isActive] = @4, [isExpendable] = @5, [ProductCatID] = @6, [ProductSubCatID] = @7, [PromoCatID] = @8, 
    [Property1Name] = @9, [Property2Name] = @10, [RackPrice] = @11, [DiscountMethod] = @12, [DiscountAmount] = @13, [SellingPrice] = @14, [Cost] = @15, [CurrencyType] = @16, [qtyPerSaleMin] = @17, 
    [qtyPerSaleMax] = @18, [SupplierID] = @19, [BrandID] = @20, [StartDate] = @21, [EndDate] = @22, [MadeIn] = @23, [TakeStockName] = @24, [LifeCycleName] = @25, [ReOrderQty] = @26, [ReOrderPoint] = @27, 
    [ReOrderDays] = @28, [PreOrderDays] = @29, [aMemo] = @30, [Updator] = @31, [DateUpdate] = @32 WHERE [ProductID] = @33',N'@0 nvarchar(4000),@1 nvarchar(4000),@2 int,@3 nvarchar(4000),@4 int,@5 int,@6 int,@7 
    int,@8 int,@9 nvarchar(4000),@10 nvarchar(4000),@11 decimal(4,4),@12 nvarchar(4000),@13 decimal(4,4),@14 decimal(4,4),@15 decimal(4,4),@16 nvarchar(4000),@17 int,@18 int,@19 int,@20 int,@21 datetime,@22 
    datetime,@23 nvarchar(4000),@24 nvarchar(4000),@25 nvarchar(4000),@26 int,@27 int,@28 int,@29 int,@30 nvarchar(4000),@31 int,@32 datetime,@33 
    int',@0=N'testxxx',@1=N'',@2=0,@3=N'',@4=0,@5=0,@6=1,@7=0,@8=0,@9=N'Color',@10=N'Size',@11=0,@12=N'%',@13=0,@14=0,@15=0,@16=N'TWD',@17=0,@18=0,@19=0,@20=0,

@21=''2013-01-20 12:28:00:000'',@22=''2063-01-20 12:28:00:000'', <--problem

@23=N'TW ',@24=N'週盤',@25=N'新品',@26=1,@27=1,@28=3,@29=1,@30=N'',@31=0,

@32=''2013-02-04 02:45:47:640'' <----problem

,@33=1

出于某种原因,所有日期时间字段都有'',因此会导致更新错误。

编辑: C#代码,BAL

public int Update(int _id, ProductManager _M)
{
    int result = _M.Product.UpdateByID(_id, _M.Product);

    return result;

}

C#代码,DAL

public virtual int UpdateByID(int _id, db_Product data)
{
    data.DateUpdate = DateTime.Now;
     using (var db = new ConnClass().ConnDB())
     {
         var result = db.Update(data, _id);
         return result;
     }
}

BAL _M.Product.UpdateByID(_id,_M.Product); 将更新发送到DAL代码以进行更新。 我检查了 ProductManager _M 中的值,dateTime值有效。

Petapoco执行命令

    UPDATE [db_Product] SET [aName] = @0, [aDesc] = @1, [EmpID] = @2, [UPCCode] = @3, [isActive] = @4, [isExpendable] = @5, [ProductCatID] = @6, [ProductSubCatID] = @7, 
[PromoCatID] = @8, [Property1Name] = @9, [Property2Name] = @10, [RackPrice] = @11, [DiscountMethod] = @12, [DiscountAmount] = @13, [SellingPrice] = @14, [Cost] = @15, [CurrencyType] = @16, [qtyPerSaleMin] = @17, [qtyPerSaleMax] = @18, [SupplierID] = @19, [BrandID] = @20, 
[StartDate] = @21, [EndDate] = @22, [MadeIn] = @23, [TakeStockName] = @24, [LifeCycleName] = @25, [ReOrderQty] = @26, [ReOrderPoint] = @27, [ReOrderDays] = @28, [PreOrderDays] = @29, 
[aMemo] = @30, [Updator] = @31, [DateUpdate] = @32 WHERE [ProductID] = @33

我已经花了几天调试这个有趣的结果......

1 个答案:

答案 0 :(得分:1)

Petapoco使用ADO.net UPDATE运行ExecuteNonQuery()语句,并返回此函数返回的值。

此功能的文档说明:

  

对于UPDATE,INSERT和DELETE语句,返回值为   受命令影响的行数。当a上存在触发器时   正在插入或更新的表,返回值包括数字   受插入或更新操作影响的行数和数字   受触发器或触发器影响的行数。对于所有其他类型的   语句,返回值为-1。如果发生回滚,则返回   值也是-1。

来源:MSDN