我试图使用 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
我已经花了几天时间调试这个有趣的结果......