执行SqlCommand.Prepare出错;
Creates a prepared version of the command on an instance of SQL Server.
但是今天执行遇到这样一个问题;
SqlCommand.Prepare method requires all parameters to have an explicitly set type.
说我的Parameter没有显式指定类型;我的SqlParamter的用法是:
SqlParameter param = new SqlParameter(paramname, paramvalue);
直接指定parametername和value
看来这样是不行,需要为这个参数指定类型和大小;
If CommandType is set to StoredProcedure, the call to Prepare should succeed, although it may cause a no-op.
假如CommandType 指定为存储过程StoredProcedure,执行也会成功,但是和不Prepare没有差别;(也就说Prepare为空操作)
Before you call Prepare, specify the data type of each parameter in the statement to be prepared. For each parameter that has a variable length data type, you must set the Size property to the maximum size needed. Prepare returns an error if these conditions are not met.
执行Prepare之前,为每个参数指定参数类型,指定大小长度,否则会返回错误;
If you call an Execute method after calling Prepare, any parameter value that is larger than the value specified by the Size property is automatically truncated to the original specified size of the parameter, and no truncation errors are returned.
Prepare之后执行Execute方法时,如果有参数值长度大于预先指定的大小,将会自动截尾,而且没有任何错误返回;
Output parameters (whether prepared or not) must have a user-specified data type. If you specify a variable length data type, you must also specify the maximum Size.
无论是否使用Prepare,返回参数(output)必须指定参数类型;