2012-02-07 66 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