我正在嘗試使用Petapoco更新一些日期時間字段,但更新總是失敗,所以我查找我的SQL分析器並找到以下執行語句。Petapoco更新日期時間錯誤
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中的值,日期時間值有效。
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
我已經花了幾天的調試這個有趣的結果....
請問你的代碼是什麼樣子? – David
你的模型定義是什麼? – Schotime
最後我解決了這個錯誤。 實際上沒有錯誤,數據確實寫入數據庫。但PetaPoco將更新返回int作爲-1,無論它是否成功更新。這似乎是一個錯誤或什麼的。 –