解决方法
唯一的区别是,您必须为返回值添加特殊参数
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; }