dinotom
dinotom

Reputation: 5162

datatable column expression error

I am getting a syntax error " Missing operand after 'Price' operator" with the following code, which should be right but obviously isn't. Any thoughts on where the error is?

    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)

Upvotes: 1

Views: 1152

Answers (2)

Tim Schmelter
Tim Schmelter

Reputation: 460058

I'm fairly sure that the exception is caused by your whitespaces in the column-names.

You should wrap the names in brackets or remove the spaces:

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

But then the next will probably walk into this trap. So in my opinion removing would be better:

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

Upvotes: 1

Harsh
Harsh

Reputation: 3751

This error comes because of an apostrophe in the value ( ' ). Check if the price value is containing any apostrophe, if its containing any, just double it.

See this link: http://aspnetresources.com/blog/apostrophe_in_rowfilter

Upvotes: 0

Related Questions