简体   繁体   English

“无法将参数值从int64转换为int32”

[英]“Failed to convert parameter value from int64 to int32”

I'm inserting few values into a SQL Server table. 我正在向SQL Server表中插入一些值。 When I'm getting the values from the front end they are strings. 当我从前端获取值时,它们是字符串。 So I need to convert them to int first, before I can insert them into the table. 所以我需要先将它们转换为int ,然后才能将它们插入表中。

I'm using this code: 我正在使用此代码:

Int64 x = Convert.ToInt64(some string value);

This x I want to insert into the table, into a column of type numeric(18,0) . 我想将此x插入表格中,类型为numeric(18,0)的列中。

When doing this conversion, I get an error 进行此转换时,出现错误

Failed to convert parameter value from int64 to int32 无法将参数值从int64转换为int32

while my all the values are just like 1000 around. 而我的所有值都只有1000左右。

Use int x = Convert.ToInt32(some string value) and it should work. 使用int x = Convert.ToInt32(some string value) ,它应该可以工作。

Your db expects a value of type Int32 . 您的数据库需要一个Int32类型的值。 SQL server won't implicitly convert a 64-bit number to a 32-bit number because of the potential loss of information. 由于潜在的信息丢失,SQL Server不会将64位数字隐式转换为32位数字。

一个Int64范围从−9,223,372,036,854,775,8089,223,372,036,854,775,807 ,正如你可以看到的是长19个字符(不包括引号),因此不会在18你数值范围适合如果你真的想使用Int64为小号码,如1000,您应该将列修改为数据类型bigint

For System.Int64 (long) in sql server side you must use bigint data type. 对于sql server端的System.Int64(长整数),必须使用bigint数据类型。 http://msdn.microsoft.com/en-us/library/ms187745.aspx http://msdn.microsoft.com/en-us/library/ms187745.aspx

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

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