誰能這麼好心地告訴我爲什麼,從Oracle數據庫讀取時,我得到以下錯誤:無法從十進制轉換爲int32
Object of type 'System.Decimal' cannot be converted to type 'System.Int32'.
它當我通過一個變量(oValue發生)類型對象成功能。我已經嘗試過演員,轉換,取消選中,截斷,幾乎整個沙包,沒有任何工作。這裏是代碼失敗的地方:
PropertyInfo property = Objects[0].GetType().GetProperty(sProperty);
property.SetValue(Objects[0], oValue, null);
任何幫助將不勝感激。
編輯:這是我到目前爲止已經試過:
(int)oValue
,Convert.ToInt32(oValue)
,Math.Truncate((decimal)ovalue)
,Decimal.Truncate((decimal)oValue)
,Decimal.ToInt32((decimal)oValue)
,並使用unchecked {}
您可以發佈您嘗試投射的變體嗎? –
很高興,我現在編輯問題 – Skulmuk