开发者

Precision problem with LINQ to dataset in VB.Net -- Double invalid cast exception

I am having some trouble with a LINQ to dataset query. I have the problem that data is returned to the dataset as a double and could be null. When I get the data into my LINQ query it truncates to one decimal place. I am wondering if anyone can tell me the best way to set the precision so that it retains two decimal places? I have tried using 'Double?' but when I do this I get an invalid cast exception. Here is a sample of my L2D query:

Dim query = _
From bb In bbdata.AsEnumerable(), _
        开发者_JAVA技巧ab In abdata.AsEnumerable() _
    Where (bb.Field(Of String)("bbID").ToUpper.Trim() = _
          ab.Field(Of String)("abID").ToUpper.Trim()) _
Order By _
            bb.Field(Of String)("Sequence") Descending, _
            bb.Field(Of String)("Name") Ascending, _
            bb.Field(Of String)("bbID").ToUpper.Trim() Ascending, _
            ab.Field(Of Decimal?)("TWO_DECIMAL_DIGIT_DOUBLE") Descending _
Select New With _
{ _
    .bbID = bb.Field(Of String)("bbID"), _
    .Weight = ab.Field(Of Decimal?)("TWO_DECIMAL_DIGIT_DOUBLE"), _
    .Sequence = bb.Field(Of String)("Sequence"), _
    .Name = bb.Field(Of String)("Name"), _
}

When I run this, the Double is truncated to one decimal and needs to be of precision where there are 2 decimal places. Any help is greatly appreciated.


Maybe it's because the Weight property rounds the value with a precision of one decimal place? I don't know what else could cause this behavior...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜