显示删除了多少行 [英] Show how many rows were deleted
问题描述
我使用 C# 程序,我的数据库在 SQL Server 2008 中.
I use C# program and my database is in SQL server 2008.
当用户从数据库中删除一些行时,我想在 Windows 应用程序中显示他/她删除了多少行.
When user deleted some rows from database, I want to show him/her in windows application how many rows deleted.
我想知道如何将 SQL 消息发送到 C# 并向用户显示.例如,当我从表中删除 4 行时,SQL 显示消息(受影响的 4 行).现在我想将数字 4 发送到我的 C# 程序.我该怎么做?谢谢.
I want to know how I can send SQL message to C# and show it for user. For example when I deleted 4 rows from table, SQL show message like (4 row(s) affected). Now I want to send number 4 to my C# program. How can I do it? Thank you.
推荐答案
如果您在 .NET 应用程序中使用 SqlCommand
来执行删除/更新,ExecuteNonQuery() 的结果
返回命令最后一条语句影响的行数.
If you are using SqlCommand
from your .NET application to perform your delete/update, the result of ExecuteNonQuery()
returns the number of rows affected by the last statement of the command.
参见 http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery.aspx.
这篇关于显示删除了多少行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!