2012-02-07 65 views
1

我得到一個語法錯誤「Price操作符」之後缺少操作數,下面的代碼應該是正確的,但顯然不是。有關錯誤發生在哪裏的任何想法?datatable列表達式錯誤

table.Columns.Add("ADR Price", GetType(Double)) 
    table.Columns.Add("ORD Price", GetType(Double)) 
    table.Columns.Add("Currency Price", GetType(Double)) 
    Dim cDiff As DataColumn = New DataColumn 
    With cDiff 
     .DataType = System.Type.GetType("System.Double") 
     .ColumnName = "Difference" 
     .Expression = "ADR Price - (ORD Price * Currency Price)" 
    End With 
    table.Columns.Add(cDiff) 

回答

1

相當 確保異常是由在列名的空格引起的。

你應該包裝在括號中的名字或刪除空格:

.Expression = "[ADR Price] - ([ORD Price] * [Currency Price])" 

但在以後可能會走進這個陷阱。所以在我看來去除會更好:

.Expression = "ADR_Price - (ORD_Price * Currency_Price)" 
+0

謝謝你[]做了伎倆 – dinotom 2012-02-07 13:21:17