通常我们应该将整数值传递给我们的存储过程,为此我们通常使用此方法command.Parameters.AddWithValue(@param1, paramValue);但是,我发现很奇怪,如果我们需要使用上面的方法将uint数据类型参数传递给存储过程,它会给...

通常我们应该将整数值传递给我们的存储过程,为此我们通常使用此方法
command.Parameters.AddWithValue("@param1", paramValue);
但是,我发现很奇怪,如果我们需要使用上面的方法将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()
解决方法:
根据reference提供的,在Sql中不支持UInt32.
Inferring a
SqlDbType
fromUInt32
is not supported.
所以传递参数为好;
command.Parameters.Add("@param1", SqlDbType.Int).Value = Convert.ToInt32(paramValue);
织梦狗教程
本文标题为:c# – UInt32的参数数据类型无效. (MS SQL Server)


基础教程推荐
猜你喜欢
- WPF+WriteableBitmap实现高性能曲线图的绘制 2023-06-28
- C#利用PrintDocument定制打印单据的小例子 2023-01-22
- centos上使用docker运行dotnetcore项目 2023-09-26
- c# 在Emit代码中如何await一个异步方法 2023-04-09
- 改进c# 代码的五个技巧(一) 2023-03-28
- C#中的多线程超时处理实践方案 2022-12-09
- Unity3D使用陀螺仪控制节点旋转 2023-02-02
- C#开发Winform实现学生管理系统 2023-06-04
- c# Linq常用的小技巧 2023-03-03
- 初学C#所需明白的那些点 2023-07-18