通常,我们应该将整数值传递到存储过程中,并且通常使用此方法
command.Parameters.AddWithValue("@param1", paramValue);
Run Code Online (Sandbox Code Playgroud)
但是,我发现很奇怪,如果我们需要使用上述方法将uint数据类型参数传递给存储过程,它将给出一个奇怪的异常。虽然它不是在代码命中ExecuteNonQuery方法时发生的,但是在此之后。我不确定为什么会这样。如果有人有什么可分享的...
这是堆栈跟踪:
at System.Data.SqlClient.MetaType.GetMetaTypeFromValue(Type dataType, Object value, Boolean inferLen, Boolean streamAllowed)
at System.Data.SqlClient.SqlParameter.GetMetaTypeOnly()
at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
at System.Data.SqlClient.SqlCommand.SetUpRPCParameters(_SqlRPC rpc, Int32 startCount, Boolean inSchema, SqlParameterCollection parameters)
at System.Data.SqlClient.SqlCommand.BuildRPC(Boolean inSchema, SqlParameterCollection parameters, _SqlRPC& rpc)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
Run Code Online (Sandbox Code Playgroud)
根据该参考提供UInt32的SQL是不支持的。
不支持
SqlDbType从中推断UInt32。
因此最好将参数传递为:
command.Parameters.Add("@param1", SqlDbType.Int).Value = Convert.ToInt32(paramValue);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3753 次 |
| 最近记录: |