简体   繁体   English

System.InvalidCastException - SQL 到 C++ - safe_cast<float></float>

[英]System.InvalidCastException - SQL to C++ - safe_cast<float>

I need to give my variable a value from SQL, this part of the code it's where the compiler stops, aparently it's maybe a convertion problem.我需要给我的变量一个来自 SQL 的值,这部分代码是编译器停止的地方,显然这可能是一个转换问题。 In my database that column is designed as float.在我的数据库中,该列被设计为浮点数。

float presion = safe_cast<float>(data[4]);

Here is the code, every value gets to his variable until it reaches the floats这是代码,每个值都会到达他的变量,直到它到达浮点数

This is my database, the value of 1.5 should go to the variable这是我的数据库,1.5的值应该是go给变量

I solved the issue, I'm gonna post it here anyway for other people with the same problem.我解决了这个问题,无论如何我都会在这里发布给其他有同样问题的人。

Just change, float for double:只需更改,浮动为双:

float presion = safe_cast<float>(data[4]);

For:为了:

float presion = safe_cast<double>(data[4]);

safe_cast is not a standard c++ type casting. safe_cast不是标准的 c++ 类型铸造。 If you change your code to:如果您将代码更改为:

float presion = dynamic_cast<double>(data[4]) ; float presion = dynamic_cast<double>(data[4]) ;

it should work.它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM