sqlserver数据库查询,在数据类型不一致时容易出错

时间:2023-03-09 22:58:18
sqlserver数据库查询,在数据类型不一致时容易出错

1、

如此句sql:

select SysNo from User_MainInfo where Ouid=@Ouid

在 User_MainInfo表中Ouid是nvarchar类型,但当我们传入的ouid参数是整型时,便容易出错,

往往会报出

”从数据类型 nvarchar 转换为 bigint 时出错。“

这样的错误

假如ouid是整型,正确的传参应为下:

sqlserver数据库查询,在数据类型不一致时容易出错

2、

c# - (数据库是tinyint,代码模型是int,会报这个错误{可以把代码模型改成byte,或者把数据库类型改成int})Property could not be set to a byte value you must set the property to a non null of type int32 - Stack Overflow

sqlserver数据库查询,在数据类型不一致时容易出错

https://*.com/questions/26524618/property-could-not-be-set-to-a-byte-value-you-must-set-the-property-to-a-non-nul