为什么 SQL 浮点数与 C# 浮点数不同 [英] Why is a SQL float different from a C# float

查看:34
本文介绍了为什么 SQL 浮点数与 C# 浮点数不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我从 DataSet 中的 DataTable 中提取了一个 DataRow.我正在访问在 SQL 中定义为浮点数据类型的列.我正在尝试将该值分配给局部变量(c# 浮点数据类型),但得到一个 InvalidCastExecption

Howdy, I have a DataRow pulled out of a DataTable from a DataSet. I am accessing a column that is defined in SQL as a float datatype. I am trying to assign that value to a local variable (c# float datatype) but am getting an InvalidCastExecption

DataRow exercise = _exerciseDataSet.Exercise.FindByExerciseID(65);
_AccelLimit = (float)exercise["DefaultAccelLimit"];  

现在,玩这个我确实让它工作了,但它没有任何意义,而且感觉不对.

Now, playing around with this I did make it work but it did not make any sense and it didn't feel right.

_AccelLimit = (float)(double)exercise["DefaultAccelLimit"];

谁能解释一下我在这里遗漏了什么?

Can anyone explain what I am missing here?

推荐答案

根据 SQLDbType 的文档.

这篇关于为什么 SQL 浮点数与 C# 浮点数不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆