sql-server – 如何从ado.net调用TSQL函数
发布时间:2020-12-12 16:33:52 所属栏目:MsSql教程 来源:网络整理
导读:我有一个在SQL Server中定义的函数(它需要一个字符串和一个int)如何用ADO.NET调用它? (如果与调用存储过程100%相同,请稍等一下,因为有很多关于调用存储过程的示例) 解决方法 唯一的区别是,您必须为返回值添加特殊参数 见:MySqlCommand call function using
我有一个在SQL Server中定义的函数(它需要一个字符串和一个int)如何用ADO.NET调用它?
(如果与调用存储过程100%相同,请稍等一下,因为有很多关于调用存储过程的示例) 解决方法唯一的区别是,您必须为返回值添加特殊参数见:MySqlCommand call function using (var connection = new SqlConnection("ConnectionString")) using (var command = connection.CreateCommand()) { command.CommandType = CommandType.StoredProcedure; command.CommandText = "MyFunction"; SqlParameter returnValue = command.Parameters.Add("@RETURN_VALUE",SqlDbType.Int); returnValue.Direction = ParameterDirection.ReturnValue; connection.Open(); command.ExecuteNonQuery(); return returnValue.Value; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |