2012-06-27 32 views
0

我想選擇一個數據表對象。當我的表達式值是82.5(double)時,代碼拋出異常。DataTable選擇:double值無法過濾

_dataSet.Tables[2].Select("ProfitShareRatio = " + Convert.ToDouble(_listrow[m]["ProfitShareRatio"])); 

P.S:ProfitShareRatio值是在雙_dataSet.Tables[2]

ERROR:

Syntax error in the expression.

at System.Data.ExpressionParser.Parse() at System.Data.DataExpression..ctor(DataTable table, String expression, Type type) at System.Data.Select..ctor(DataTable table, String filterExpression, String sort, DataViewRowState recordStates) at System.Data.DataTable.Select(String filterExpression)

編輯2: 相同出錯當我使用十進制。

_dataSet.Tables[2].Select("ProfitShareRatio = " + Convert.ToDecimal(_listrow[m]["ProfitShareRatio"])); 

P.S 2:問題是Convert.ToDecimal(_listrow[m]["ProfitShareRatio"])是逗號像82,50 我需要用點狀82.50

+1

出於興趣,_dataSet.Tables [2] .Select(「ProfitShareRatio = 82.5」)工作嗎?你確定_dataSet.Tables [2]中ProfitShareRation的數據類型是雙倍的嗎?那麼_dataSet.Tables [2] .Columns [「ProfitShareRation」] .DataType給你帶來了什麼? – dash

+0

@maycil能否向我們解釋_listrow [m] [「ProfitShareRatio」]? – HichemSeeSharp

+0

@dash _dataSet.Tables [2] .Select(「ProfitShareRatio = 82.5」)正在工作。 _dataSet.Tables [2] [「ProfitShareRatio」]是十進制數。 – maycil

回答

0
String.Format(new System.Globalization.CultureInfo("en-US"),"ProfitShareRatio = {0}",Convert.ToDecimal(_listrow[m]["ProfitShareRatio"])) 

感謝所有返回值返回值。將文化轉換爲en-US可以解決問題。字符串格式結果是「ProfitShareRatio = 82.5」

+1

我以前的回答很接近,雖然我們不知道你有文化問題。 – HichemSeeSharp

+0

是的,你是對的。我注意到在不同文化機器上的問題。 – maycil