?求解精度问题:VC的float与SQL的decimal?

bololucky 2006-09-13 02:03:05
存储过程中有一个decimal(18,0)的字段,现在要将一个vc的float的变量放进去,但是直接插入会出现精度无效的错误

_variant_t v_Score = _variant_t( Score );

pScore.CreateInstance(__uuidof(Parameter));
pScore = m_pCommand -> CreateParameter
(
_bstr_t( "Score" ),
adNumeric,
adParamInput,

v_Score
);
m_pCommand -> Parameters -> Append(pScore);
Execute的时候就弹出精度无效的错误了。。。
...全文
695 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
一条晚起的虫 2007-01-15
  • 打赏
  • 举报
回复
decimal对应的应该是double型
var.dblVal = a;
hhcjb 2007-01-15
  • 打赏
  • 举报
回复
发错了,不好意思,VarR8FromDec
hhcjb 2007-01-15
  • 打赏
  • 举报
回复
VarDecCmpR8
一条晚起的虫 2006-09-14
  • 打赏
  • 举报
回复
_variant_t var;
var.ChangeType(VT_DECIMAL);
var = a; //??
bololucky 2006-09-14
  • 打赏
  • 举报
回复
继续在线等!!!
bololucky 2006-09-14
  • 打赏
  • 举报
回复
lfchen的方法试过了。。。不行。。。
jun_01贴的E文勉强看懂,那一句代码看不明白怎么用。。。
jun_01 2006-09-14
  • 打赏
  • 举报
回复
ANSI SQL Data Types Mapped to C++ Data Types
ANSI SQL data type C++ data type
CHAR
CString

DECIMAL
CString 1

1. ANSI DECIMAL and NUMERIC map to CString because SQL_C_CHAR is the default ODBC transfer type.
jun_01 2006-09-14
  • 打赏
  • 举报
回复
Supported SQL Data Types in C and C++
Certain predefined C and C++ data types correspond to the database manager column types. Only these C/C++ data types can be declared as host variables.

The following table shows the C/C++ equivalent of each column type. When the precompiler finds a host variable declaration, it determines the appropriate SQL type value. The database manager uses this value to convert the data exchanged between the application and itself.

Note:
There is no host variable support for the DATALINK data type in any of the DB2 host languages.
Table 17. SQL Data Types Mapped to C/C++ Declarations SQL Column Type1 C/C++ Data Type SQL Column Type Description
SMALLINT
(500 or 501)
short
short int
sqlint16
16-bit signed integer
INTEGER
(496 or 497)
long
long int
sqlint322
32-bit signed integer
BIGINT
(492 or 493)
long long
long
__int64
sqlint643
64-bit signed integer
REAL4
(480 or 481)
float Single-precision floating point
DOUBLE5
(480 or 481)
double Double-precision floating point
DECIMAL(p,s)
(484 or 485)
No exact equivalent; use double Packed decimal
(Consider using the CHAR and DECIMAL functions to manipulate packed decimal fields as character data.)

jun_01 2006-09-14
  • 打赏
  • 举报
回复
DECIMAL FAR* pdecVal // VT_BYREF|VT_DECIMAL.
bololucky 2006-09-13
  • 打赏
  • 举报
回复
在线等待啊!各位大侠帮帮忙啊!
bololucky 2006-09-13
  • 打赏
  • 举报
回复
楼上的。。。瀑布汗啊!。。。
bololucky 2006-09-13
  • 打赏
  • 举报
回复
急求解答啊!高手们帮帮忙啊!!!
jun_01 2006-09-13
  • 打赏
  • 举报
回复
看错了,疯,当我没说
jun_01 2006-09-13
  • 打赏
  • 举报
回复
decimal(18,0)?

用来放身份证吗? 最好用char(18)
bololucky 2006-09-13
  • 打赏
  • 举报
回复
怎么还没有人啊。。。急求答案啊!!

4,017

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧