English 中文(简体)
如果无输电会受到影响,SqlCommand.ExecuteNon Query()的回报应该是什么价值?
原标题:What value should .net SqlCommand.ExecuteNonQuery() return if no rows are affected?

我有以下法典:

int result = -1;
StringBuilder sb = new StringBuilder();
SqlCommand cmd = MyConnection.
sb.AppendLine("delete from Table1 where ID in");
sb.AppendLine("(select id from Table1 t1 where  not exists(select * from Table2 t2 where t2.Table1ID = t1.ID))");
cmd.CommandText = sb.ToString();
result = cmd.ExecuteNonQuery();
_log.Info("StoredXMLDocument Records Deleted: " + result.ToString());

简言之,以更可读的形式,是:

delete from Table1 where ID in
(select id from Table1 t1 where  not exists(select * from Table2 t2 where t2.Table1ID = t1.ID))

我知道,库克在数据库中直接执行时,就删除了一行。 然而,当该守则运行时,result获得1. 。 我期望它为0。 表1没有触发因素。 我失踪了吗? 为什么是1?

<>Addendum: ok,在我管理数据库中的舱面时,删除了一行。 请注意,在所有测试之前,我从仅为此目的而节省的备份I中恢复数据库。 今天上午或昨天下午,我戴上了一条row子,在恢复后是的。 我不想让我戴高射药,今天下午再次讨论这个问题。 抱着希望更清楚的思维。

最佳回答

填表<0><0>。

在<代码>之前和之后对<代码>进行对比 DELETE。

问题回答

作为附带说明,你的询问可以简化为:

delete from Table1 where ID not in (select Table1ID from Table2)

为了利益:

delete from Table1 where 1 = 0 --we know this will delete no rows

另外,请确认在<编码>上是否有任何触发因素。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签