Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UInt32的参数数据类型无效。(MS SQL Server)_C#_Sql_Sql Server - Fatal编程技术网

C# UInt32的参数数据类型无效。(MS SQL Server)

C# UInt32的参数数据类型无效。(MS SQL Server),c#,sql,sql-server,C#,Sql,Sql Server,一般来说,我们应该将整数值传递给存储过程,为此,我们通常使用这种方法 command.Parameters.AddWithValue("@param1", paramValue); 但是,我发现非常奇怪的是,如果我们需要使用上述方法将uint数据类型参数传递给存储过程,它会给出一个奇怪的异常。虽然不是在代码命中ExecuteOnQuery方法时,而是在之后。我不知道为什么会这样。如果有人有什么要分享的,请 以下是堆栈跟踪: at System.Data.SqlClient.MetaTyp

一般来说,我们应该将整数值传递给存储过程,为此,我们通常使用这种方法

command.Parameters.AddWithValue("@param1", paramValue);
但是,我发现非常奇怪的是,如果我们需要使用上述方法将uint数据类型参数传递给存储过程,它会给出一个奇怪的异常。虽然不是在代码命中ExecuteOnQuery方法时,而是在之后。我不知道为什么会这样。如果有人有什么要分享的,请

以下是堆栈跟踪:

   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()
根据提供的
UInt32
在Sql中不受支持

不支持从
UInt32
推断
SqlDbType

因此,最好将参数传递为

command.Parameters.Add("@param1", SqlDbType.Int).Value = Convert.ToInt32(paramValue);
您可以尝试以下方法:

cmd.Parameters.Add(new SqlParameter("@param", SqlDbType.Int));

您可以对此进行检查以了解更多信息。

UInt16在ADO.NET中不受支持。使用Int64而不是UInt16。有关更多信息,请访问:
你可以像传递字符串一样传递它。使用UInt32.ToString()。它的工作非常完美

我们不是超人,因此请发布您的错误。我个人避免使用
AddWithValue
,而是使用
Add
,指定参数类型(例如
SqlDbType.Int
),然后设置
属性。这清楚地表明了您真正想要访问数据库的类型。