简体   繁体   English

SqlCeException:表达式评估导致溢出

[英]SqlCeException: Expression evaluation caused an overflow

There are other questions with similar sounding titles, but my case appears to be unique, so here goes:还有其他类似标题的问题,但我的情况似乎是独一无二的,所以这里是:

This problem seems to be centered on using Decimal values in my table.这个问题似乎集中在在我的表中使用 Decimal 值。 If I create a table and leave out the Precision and Scale parameters, the table creates but all of my data is inserted as an integer value.如果我创建一个表并忽略 Precision 和 Scale 参数,则该表会创建,但我的所有数据都作为 integer 值插入。 If I create a table and specify the Precision and Scale parameters, I get the exception thrown below my SQL Statements.如果我创建一个表并指定 Precision 和 Scale 参数,则会在我的 SQL 语句下方抛出异常。

Here is my Create Table statement:这是我的创建表语句:

CREATE TABLE RMCoil 
(
    ID int IDENTITY (100,1) PRIMARY KEY
,   Modified DateTime NOT NULL
,   [Type] nchar(1)
,   [Model] nvarchar(50)
,   [CPPartNo] nvarchar(50)
,   [FH] decimal(10,10)
,   [FL] decimal(10,10)
,   [FPI] int
,   [TR] nchar(1)
,   [FinThk] decimal(10,10)
,   [FinMat] nchar(1)
,   [TubeOD] int
,   [Rifled] nchar(1)
,   [WallThk] decimal(10,10)
,   [CKT] int
,   [RD] int
,   [Split] nvarchar(50)
,   [CKT1] int
,   [CKT2] int
,   [CKT3] int
,   [CKT4] int
,   [Feed1] int
,   [Feed2] int
,   [Feed3] int
,   [Feed4] int
,   [Altitude] decimal(10,10)
,   [Connection] decimal(10,10)
,   [Header] decimal(10,10)
) 

SqlCeCommand.ExecuteNonQuery() returns -1, but this must be OK because it creates the table. SqlCeCommand.ExecuteNonQuery() 返回 -1,但这一定没问题,因为它创建了表。

If a table exists, the SELECT statement works fine:如果存在表,则 SELECT 语句可以正常工作:

SELECT
    ID
,   Modified
,   [ID]
,   [MODIFIED]
,   [Model]
,   [VoltCode]
,   [Vendor]
,   [Product]
,   [ACRLA208SP]
,   [LRA208SP]
,   [ACRLA230SP]
,   [LRA230SP]
,   [ACRLA208]
,   [LRA208]
,   [ACRLA230]
,   [LRA230]
,   [ACRLA380]
,   [LRA380]
,   [ACRLA460]
,   [LRA460]
,   [ACRLA575]
,   [LRA575]
,   [ECRLA208]
,   [ECRLA230]
,   [ECRLA460]
,   [ECRLA575]
,   [Displacement]
,   [CF0]
,   [CF1]
,   [CF2]
,   [CF3]
,   [CF4]
,   [CF5]
,   [CF6]
,   [CF7]
,   [CF8]
,   [CF9]
,   [CF10]
,   [CF11]
,   [CF12]
,   [CF13]
,   [CF14]
,   [CF15]
,   [CF16]
,   [CF17]
,   [CF18]
,   [CF19]
,   [CF20]
,   [CF21]
,   [CF22]
,   [CF23]
,   [CF24]
,   [CF25]
,   [CF26]
,   [CF27]
,   [CF28]
,   [CF29]
,   [CF30]
,   [CF31]
,   [CF32]
,   [CF33]
,   [CF34]
,   [CF35]
,   [CF36]
,   [CF37]
,   [CF38]
,   [CF39] 
FROM RMCompressor

SqlCeCommand.CommandText.Length = 633 SqlCeCommand.CommandText.Length = 633

INSERT INTO RMCompressor
(
    Modified
,   [Model]
,   [VoltCode]
,   [Vendor]
,   [Product]
,   [ACRLA208SP]
,   [LRA208SP]
,   [ACRLA230SP]
,   [LRA230SP]
,   [ACRLA208]
,   [LRA208]
,   [ACRLA230]
,   [LRA230]
,   [ACRLA380]
,   [LRA380]
,   [ACRLA460]
,   [LRA460]
,   [ACRLA575]
,   [LRA575]
,   [ECRLA208]
,   [ECRLA230]
,   [ECRLA460]
,   [ECRLA575]
,   [Displacement]
,   [CF0]
,   [CF1]
,   [CF2]
,   [CF3]
,   [CF4]
,   [CF5]
,   [CF6]
,   [CF7]
,   [CF8]
,   [CF9]
,   [CF10]
,   [CF11]
,   [CF12]
,   [CF13]
,   [CF14]
,   [CF15]
,   [CF16]
,   [CF17]
,   [CF18]
,   [CF19]
,   [CF20]
,   [CF21]
,   [CF22]
,   [CF23]
,   [CF24]
,   [CF25]
,   [CF26]
,   [CF27]
,   [CF28]
,   [CF29]
,   [CF30]
,   [CF31]
,   [CF32]
,   [CF33]
,   [CF34]
,   [CF35]
,   [CF36]
,   [CF37]
,   [CF38]
,   [CF39])
 VALUES
(
    GetDate()
,   @Model
,   @VoltCode
,   @Vendor
,   @Product
,   @ACRLA208SP
,   @LRA208SP
,   @ACRLA230SP
,   @LRA230SP
,   @ACRLA208
,   @LRA208
,   @ACRLA230
,   @LRA230
,   @ACRLA380
,   @LRA380
,   @ACRLA460
,   @LRA460
,   @ACRLA575
,   @LRA575
,   @ECRLA208
,   @ECRLA230
,   @ECRLA460
,   @ECRLA575
,   @Displacement
,   @CF0
,   @CF1
,   @CF2
,   @CF3
,   @CF4
,   @CF5
,   @CF6
,   @CF7
,   @CF8
,   @CF9
,   @CF10
,   @CF11
,   @CF12
,   @CF13
,   @CF14
,   @CF15
,   @CF16
,   @CF17
,   @CF18
,   @CF19
,   @CF20
,   @CF21
,   @CF22
,   @CF23
,   @CF24
,   @CF25
,   @CF26
,   @CF27
,   @CF28
,   @CF29
,   @CF30
,   @CF31
,   @CF32
,   @CF33
,   @CF34
,   @CF35
,   @CF36
,   @CF37
,   @CF38
,   @CF39
)

SqlCeException: Expression evaluation caused an overflow. [ Name of function (if known) = ] SqlCeException: Expression evaluation caused an overflow. [ Name of function (if known) = ] Expression evaluation caused an overflow. [ Name of function (if known) = ] HResult: -2147217900 NativeError: 25901 Source: SQL Server Compact ADO.NET Data Provider Expression evaluation caused an overflow. [ Name of function (if known) = ] HResult: -2147217900 NativeError: 25901来源: SQL Server Compact ADO.NET Data Provider

Does anyone know how to read the HResult or NativeError?有谁知道如何阅读 HResult 或 NativeError?

My INSERT statement isn't too long or something, is it?我的 INSERT 语句不是太长或什么的,是吗?

If it helps, I've uploaded my Visual Studio 2010 C# project SqlCeTool (without the binaries) >> HERE << (I will remove my project link after this issue is resolved).如果有帮助,我已经上传了我的 Visual Studio 2010 C# 项目SqlCeTool (没有二进制文件) >> HERE << (解决此问题后我将删除我的项目链接)。

You are creating a decimal values with equal precision and scale, is that intended?您正在创建具有相同精度和比例的十进制值,这是有意的吗? As it stands, you are creating fields like Altitude which can contain values of.0000000000 to.9999999999 (assuming I counted right).就目前而言,您正在创建像 Altitude 这样的字段,它可以包含 .0000000000 到 .9999999999 的值(假设我数对了)。 I believe you will want to adjust your precision and scale to be something like Altitude(20,10)我相信您会希望将精度和比例调整为 Altitude(20,10)

Books On Line article discussing Precision, Scale, and Length Money quote: "Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number. For example, the number 123.45 has a precision of 5 and a scale of 2."在线书籍文章讨论精度、比例和长度金钱引用:“精度是数字中的位数。比例是数字中小数点右侧的位数。例如,数字 123.45 有精度为 5,比例为 2。”

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

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