SqlParameter代码:
SqlParameter[] paras = {
new SqlParameter("@Number",0),
new SqlParameter("@Turntablestate",11),
new SqlParameter("@MachineCode",ConfigurationManager.AppSettings["SystemNumber"]),
new SqlParameter("@Turntableid",tongInfo.Turntableid)
};
LisSQLHelper.executecommand(sql, paras);
执行时异常错误:
System.Exception:“执行update SM_JY_STATE set Number=@Number,Turntablestate=@Turntablestate where MachineCode=@MachineCode and Turntableid=@Turntableid失败;参数化查询 '(@Number bigint,@Turntablestate int,@MachineCode nvarchar(2),@Tu' 需要参数 '@Number',
正确解决方案:
SQLparameter使用时有一个注意点:SqlParameter如果传入0会变成NULL
错误测试代码:
new SqlParameter("@Number",0),
调试时候发现@id值变成null,无法正确调用。
正确写法:
new SqlParameter("@Number",Convert.ToInt32(0)),
微软官方解释:微软官方的参考文档:
SqlParameter 构造函数