简体   繁体   English

将数据添加到数据库时发生异常-将int转换为数字数据类型时发生溢出错误

[英]Exception while adding data to to the database -overflow error converting int to data type numeric

I'm getting an exception for some data sets when I add them to the table. 将某些数据集添加到表中时,我遇到了例外。 Data is coming from a WEB API and there are no exceptions for the following data columns. 数据来自WEB API,以下数据列也不例外。

"RRP": 2.98074513,
"Cost": 2.533633360

But when it is trying to add the following data sets it shows an SQL Exception 但是,当尝试添加以下数据集时,它会显示SQL异常

"RRP": 2.92,
"Cost": 2.4820

and this - 和这个 -

"RRP": 4.90,
"Cost": 4.1650

The exception is "Core .Net SqlClient Data Provider, MessageArithmetic overflow error converting int to data type numeric" 例外是“ Core .Net SqlClient数据提供程序,MessageArithmetic溢出错误将int转换为数值类型的数据”

SQL Table structure - SQL表结构-

CREATE TABLE [dbo].[DailyConsumptionLogs](
    [UsageLineId] [int] IDENTITY(1,1) NOT NULL,
    [ResourceId] [varchar](500) NOT NULL,
    [RRP] [numeric](15, 13) NOT NULL,
    [Cost] [numeric](15, 13) NULL
) ON [PRIMARY]

Insert statement executed in C# - 在C#中执行的插入语句-

string sql_command = String.Format(@"INSERT INTO DailyConsumptionLogs(
                                                        ResourceId,
                                                        RRP,
                                                        Cost) 
                                  VALUES ('{0}','{1}','{2}')",
                                               item.ResourceId,
                                               item.RRP,
                                               item.Cost);
  1. Could you share the value of the sql_command after the execution of the assignment line? 执行分配行后,您能否共享sql_command的值? Both correct and incorrect. 正确和错误。
  2. How are item.RRP, item.Cost defined? 如何定义item.RRP,item.Cost?
  3. Do you have any exception inserting directly to the DB? 您是否有直接插入数据库的异常?

    INSERT INTO DailyConsumptionLogs(ResourceId, RRP, Cost) VALUES (1,4.90,4.1650) INSERT INTO DailyConsumptionLogs(ResourceId, RRP, Cost) VALUES (1,'2.92', '2.4820') 插入DailyConsumptionLogs(ResourceId,RRP,成本)值(1,4.90,4.1650)插入DailyConsumptionLogs(ResourceId,RRP,成本)值(1,'2.92','2.4820')

  1. This is the command taken after using a breakpoint - 这是使用断点后采取的命令-

Correct command 正确的命令

  INSERT INTO DailyConsumptionLogs(ResourceId,RRP,Cost)VALUES('03E2F28B',2.98074513,2.53363336)

Exception Command 异常命令

INSERT INTO DailyConsumptionLogs (ResourceId,RRP,Cost)v VALUES ('03E2F28B',4.9,4.165)
  1. Both are defined as numeric(15, 13) data type 两者都定义为numeric(15, 13)数据类型

  2. Yes insert it directly to the DB gets the following exception in SQL server 是的,将其直接插入数据库中会在SQL Server中获得以下异常

Arithmetic overflow error converting int to data type numeric. 将int转换为数值数据类型的算术溢出错误。 The statement has been terminated. 该语句已终止。

暂无
暂无

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

相关问题 c# 中的 ExecuteNonQuery() 抛出异常 - 将数字转换为数据类型数字的算术溢出错误 - ExecuteNonQuery() from c# throwing exception - arithmetic overflow error converting numeric to data type numeric 使用C#和SQL Server将int转换为数据类型数值的算术溢出错误 - Arithmetic overflow error converting int to data type numeric using C# and SQL Server 在SQL Server 2008中将varchar转换为数值数据类型时发生算术溢出错误 - An arithmetic overflow error occurred while converting varchar to numeric data type in SQL Server 2008 WINFORM算术溢出错误将表达式转换为数据类型int - WINFORM arithmetic overflow error converting expression to data type int 将表达式转换为数据类型 int 的算术溢出错误 - Arithmetic overflow error converting expression to data type int 将varchar转换为数值数据类型的算术溢出错误。 尝试从数据库读取时并非每次都会发生 - Arithmetic overflow error converting varchar to data type numeric. when trying to read from a database DOES NOT happen every time 流利的NHibernate在插入/保存时导致“将数字转换为数据类型数字的算术溢出错误” - Fluent NHibernate cause an “Arithmetic overflow error converting numeric to data type numeric” on insert/save 将数字转换为数据类型数字时出错 - Error when converting numeric to data type numeric 将varchar转换为数值数据类型的算术溢出错误。 asp.net中的错误 - Arithmetic overflow error converting varchar to data type numeric. Error in asp.net 将数据类型nvarchar转换为int时出错 - 执行存储过程时 - Error converting data type nvarchar to int - while executing stored procedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM