什么是更好地从存储过程返回一个值到.NET:OUTPUT参数或的ExecuteScalar? [英] What is better to return single value from stored procedure to .Net: OUTPUT parameter or ExecuteScalar?
问题描述
我需要创建一个需要返回的一些记录计数的存储过程。我使用的.Net读结果。
I need to create a stored procedure that needs to return a count of some records. I'm using .Net to read the result.
我可以使用输出
参数返回值的或的我可以做一个 SELECT COUNT(*)
在存储过程中和使用的 SqlCommand.ExecuteScalar 阅读。
I can use an OUTPUT
parameter to return the value or I could do a select count(*)
in the stored procedure and use a SqlCommand.ExecuteScalar to read it.
什么是好,什么原因呢?
What is better and why?
推荐答案
看看这个MSDN文章:的性能比较:数据访问技术
Check out this MSDN article: Performance Comparison: Data Access Techniques
文章显示了在 GetOrderStatus
性能测试OUTPUT参数和ExecuteScaler之间的性能是相同的在检索一个单值,但的ExecuteScalar需要更少的code。
The article shows in the performance test for GetOrderStatus
that the performance between OUTPUT parameter and ExecuteScaler is the same for retreiving a single value, but ExecuteScalar requires less code.
下面是关于不会输出参数其他一些有趣的想法:
有什么不对输出参数。我喜欢输出PARAMS思想打破这个职位的函数
的基本思路。
Here are some other interesting thoughts about not going for the OUTPUT parameter:
What's wrong with output parameters. I like the thought of Output params break the fundamental idea of a function
in that post.
这篇关于什么是更好地从存储过程返回一个值到.NET:OUTPUT参数或的ExecuteScalar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!