2016-08-08 39 views
2

我想從FoxPro中獲取表格到C#。我正在使用以下聲明;OleDB無法確定十進制值

sqlCmd.CommandText = @"SELECT ew.ew_pplid, ew.ew_name, ew.ew_from, ew_to, ew.ew_totdays 
         FROM empwork ew 
         INNER JOIN employs emp ON ew.ew_pplid = emp.em_pplid 
         WHERE emp.em_netname NOT LIKE '' 
         AND TRIM(emp.em_netname) <> '' 
         AND emp.em_type <> 2 
         AND ew.ew_from > ?"; 
sqlCmd.Parameters.AddWithValue("pDate", Convert.ToDateTime("01/08/2016")); 

但我得到一個我從未見過的錯誤;

The Provider could not determine the Decimal value. For example, the row was just created, the default for the Decimal column was not available, and the consumer had not yet set a new Decimal value.

有沒有人見過這個錯誤,如果是這樣我怎麼能解決這個得到什麼?

+0

另外,在查詢中使用TRIM()和LIKE意味着它不太可能被Rushmore優化,並且對於大型數據集可能會很慢。 –

回答

1

如果要是上的日期時間是窒息一個假消息,你可能有輕微的改變通過

AND ew.ew_from > CTOD(?)"; 

和參數作爲只是日期的字符串嘗試

sqlCmd.Parameters.AddWithValue("pDate", "01/08/2016"); 

VFP的命令CTOD()表示字符到日期,並且由於您已經處於預期的月/日/年格式,因此應該通過。

如果失敗實際上發生在另一個字段(例如「ew.ew_totdays」)上,則始終可以通過更新查詢來限制僅返回ID標識的字段,而不要使用where子句。然後如果它通過,一次添加一個字段。數據中的某處可能有一個NULL值。

如果所有字段都正常,那麼您可能必須一次應用基於WHERE子句和剝離標準的查詢,直到全部應用。