繁体   English   中英

存储过程插入截断的值

[英]stored procedure inserts truncated value

我有一个使用几个输入参数的存储过程,并将它们插入到Sql数据库中。 @CustomerId一个参数存在问题,插入到数据库时会被截断(但并非总是如此)。

C#:

cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@CustomerId", Convert.ToInt32(customerId));
cmd.Connection = sqlConn;
sqlConn.Open();
cmd.ExecuteNonQuery();
sqlConn.Close();

SQL SP: @CustomerId int

INSERT INTO dbo.tblOffers 
(CustomerId)
VALUES
    (@CustomerId)

sql表数据类型:

CustomerId int not null

示例:564276117被截断为4276117(但并非一直都这样,并且正确插入了大于560000000的值)我在做什么错? 谢谢

尝试使用Parameters.Add()方法代替AddWithValue

cmd.Parameters.Add("@CustomerId",SqlDbType.Int).Value=CustomerID;

您可以尝试以下操作:使用ToInt64

cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@CustomerId", Convert.ToInt64(customerId));
cmd.Connection = sqlConn;
sqlConn.Open();
cmd.ExecuteNonQuery();
sqlConn.Close();

暂无
暂无

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

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