G
Guest
Calling DataAdatper.Update silently truncates Decimal fields that exceed the
specified scale of the underlying database type. For example, with a scale of
2, the value 1.666 is truncated to 1.66 instead of rounded to 1.67 as you
might expect, and as it works when interacting with the database directly.
It's pernicious because it's done behind the scenes. The .Net Decimal type
doesn't have fixed scale, it adjusts to what you put in it. so you can put
these values in your DataSet with no sign of danger. It isn't until you call
Update that the problem manifests itself. The best part is that it does it
silently. I've tried but failed to come up with plausible design rationale
for this.
Has anyone else run into this? Is it by design? What's the reasoning behind
truncating intead of rounding? Shouldn't it at least throw an exception?
Yes, I know you could avoid this by rounding ahead of time, but that implies
building a whole gatekeeping layer that will have to check through the
underlying Sql types and scales and build a rounding call. That seems lame.
Thanks in advance for any insight.
specified scale of the underlying database type. For example, with a scale of
2, the value 1.666 is truncated to 1.66 instead of rounded to 1.67 as you
might expect, and as it works when interacting with the database directly.
It's pernicious because it's done behind the scenes. The .Net Decimal type
doesn't have fixed scale, it adjusts to what you put in it. so you can put
these values in your DataSet with no sign of danger. It isn't until you call
Update that the problem manifests itself. The best part is that it does it
silently. I've tried but failed to come up with plausible design rationale
for this.
Has anyone else run into this? Is it by design? What's the reasoning behind
truncating intead of rounding? Shouldn't it at least throw an exception?
Yes, I know you could avoid this by rounding ahead of time, but that implies
building a whole gatekeeping layer that will have to check through the
underlying Sql types and scales and build a rounding call. That seems lame.
Thanks in advance for any insight.