I'm executing the .ExecuteNonQuery method of a SQLCommand object, with the following SQL: UPDATE BUDGET_ACCOUNT SET Deleted = 1, DATE_DELETED = GetDate(), MODIFIED_BY_ID_FK = 1 WHERE ID = 951956 If I copy this SQL code to Query Analyzer, it returns 1 record affected. However, if I run it in ADO.NET, it returns 2. 'ID' is the primary key, and is an auto numbered identity field... I do not have a 'delete' trigger on the table. Running VS 2003. SQL Server 2000 SP3. Win2K.
[quoted text, click to view] "Harry F. Harrison" <Harry_Harrison@sbcss.k12.ca.us> wrote in message news:u0TVDN3jEHA.2948@TK2MSFTNGP11.phx.gbl... > I'm executing the .ExecuteNonQuery method of a SQLCommand object, with the > following SQL: > > UPDATE BUDGET_ACCOUNT > SET Deleted = 1, DATE_DELETED = GetDate(), MODIFIED_BY_ID_FK = 1 > WHERE ID = 951956 > > If I copy this SQL code to Query Analyzer, it returns 1 record affected. > > However, if I run it in ADO.NET, it returns 2. > > 'ID' is the primary key, and is an auto numbered identity field... > > I do not have a 'delete' trigger on the table. > > Running VS 2003. SQL Server 2000 SP3. Win2K. > >
You could use this instead. Bind an output parameter to @ROWS. UPDATE BUDGET_ACCOUNT SET Deleted = 1, DATE_DELETED = GetDate(), MODIFIED_BY_ID_FK = 1 WHERE ID = 951956; SET @ROWS = @@ROWCOUNT David
Hi, try with a SET NOCOUNT ON at the begining of the SP. Regards Joyjit [quoted text, click to view] "Harry F. Harrison" <Harry_Harrison@sbcss.k12.ca.us> wrote in message news:u0TVDN3jEHA.2948@TK2MSFTNGP11.phx.gbl... > I'm executing the .ExecuteNonQuery method of a SQLCommand object, with the > following SQL: > > UPDATE BUDGET_ACCOUNT > SET Deleted = 1, DATE_DELETED = GetDate(), MODIFIED_BY_ID_FK = 1 > WHERE ID = 951956 > > If I copy this SQL code to Query Analyzer, it returns 1 record affected. > > However, if I run it in ADO.NET, it returns 2. > > 'ID' is the primary key, and is an auto numbered identity field... > > I do not have a 'delete' trigger on the table. > > Running VS 2003. SQL Server 2000 SP3. Win2K. > >
Hi Harry, It's the first time I hear about something like this. Is this something you can reproduce in an stand-alone program? If so, I'd be glad to take a look if you could post it to the newgroup or email me directly. Thanks, -- Pablo Castro Program Manager - ADO.NET Team Microsoft Corp. This posting is provided "AS IS" with no warranties, and confers no rights. [quoted text, click to view] "Harry F. Harrison" <Harry_Harrison@sbcss.k12.ca.us> wrote in message news:u0TVDN3jEHA.2948@TK2MSFTNGP11.phx.gbl... > I'm executing the .ExecuteNonQuery method of a SQLCommand object, with the > following SQL: > > UPDATE BUDGET_ACCOUNT > SET Deleted = 1, DATE_DELETED = GetDate(), MODIFIED_BY_ID_FK = 1 > WHERE ID = 951956 > > If I copy this SQL code to Query Analyzer, it returns 1 record affected. > > However, if I run it in ADO.NET, it returns 2. > > 'ID' is the primary key, and is an auto numbered identity field... > > I do not have a 'delete' trigger on the table. > > Running VS 2003. SQL Server 2000 SP3. Win2K. > >
I created a stand-alone sample, with code to create a new table, and was not able to duplicate it. :) After further investigation, I realized that I have an update trigger on the table to update a field with the current date-time. When I disabled the trigger, ExecuteNonQuery would return 1 - the same as Query Analyzer. So, I wonder why Query Analyzer is only returning 1,even when the trigger is enabled. Which result is 'correct'? [quoted text, click to view] "Pablo Castro [MS]" <pablocas@online.microsoft.com> wrote in message news:OaTbaOGkEHA.1348@TK2MSFTNGP15.phx.gbl... > Hi Harry, > > It's the first time I hear about something like this. Is this something you > can reproduce in an stand-alone program? If so, I'd be glad to take a look > if you could post it to the newgroup or email me directly. > > Thanks, > > -- > Pablo Castro > Program Manager - ADO.NET Team > Microsoft Corp. > > This posting is provided "AS IS" with no warranties, and confers no rights. > > > "Harry F. Harrison" <Harry_Harrison@sbcss.k12.ca.us> wrote in message > news:u0TVDN3jEHA.2948@TK2MSFTNGP11.phx.gbl... > > I'm executing the .ExecuteNonQuery method of a SQLCommand object, with the > > following SQL: > > > > UPDATE BUDGET_ACCOUNT > > SET Deleted = 1, DATE_DELETED = GetDate(), MODIFIED_BY_ID_FK = 1 > > WHERE ID = 951956 > > > > If I copy this SQL code to Query Analyzer, it returns 1 record affected. > > > > However, if I run it in ADO.NET, it returns 2. > > > > 'ID' is the primary key, and is an auto numbered identity field...
hm, interesting. I don't know why the Query Analyzer folks decided to show side-effects they way you mention below, but I'll try to find out. SqlClient simply returns the sum of all the affected rows as reported by the server. As to which one is correct, well, I guess that's the kind of question you can argue for both ways, depending on what are your particular needs or scenario. In the next release (Whidbey), the connection has an event that let's you get notified of each completed statements along with the number of rows it affected. -- Pablo Castro Program Manager - ADO.NET Team Microsoft Corp. This posting is provided "AS IS" with no warranties, and confers no rights. [quoted text, click to view] "Harry F. Harrison" <Harry_Harrison@sbcss.k12.ca.us> wrote in message news:%23DLpLCUkEHA.1800@TK2MSFTNGP15.phx.gbl... > I created a stand-alone sample, with code to create a new table, and was not > able to duplicate it. :) > > After further investigation, I realized that I have an update trigger on the > table to update a field with the current date-time. > > When I disabled the trigger, ExecuteNonQuery would return 1 - the same as > Query Analyzer. > > So, I wonder why Query Analyzer is only returning 1,even when the trigger is > enabled. > > Which result is 'correct'? > > > "Pablo Castro [MS]" <pablocas@online.microsoft.com> wrote in message > news:OaTbaOGkEHA.1348@TK2MSFTNGP15.phx.gbl... > > Hi Harry, > > > > It's the first time I hear about something like this. Is this something > you > > can reproduce in an stand-alone program? If so, I'd be glad to take a look > > if you could post it to the newgroup or email me directly. > > > > Thanks, > > > > -- > > Pablo Castro > > Program Manager - ADO.NET Team > > Microsoft Corp. > > > > This posting is provided "AS IS" with no warranties, and confers no > rights. > > > > > > "Harry F. Harrison" <Harry_Harrison@sbcss.k12.ca.us> wrote in message > > news:u0TVDN3jEHA.2948@TK2MSFTNGP11.phx.gbl... > > > I'm executing the .ExecuteNonQuery method of a SQLCommand object, with > the > > > following SQL: > > > > > > UPDATE BUDGET_ACCOUNT > > > SET Deleted = 1, DATE_DELETED = GetDate(), MODIFIED_BY_ID_FK = 1 > > > WHERE ID = 951956 > > > > > > If I copy this SQL code to Query Analyzer, it returns 1 record affected. > > > > > > However, if I run it in ADO.NET, it returns 2. > > > > > > 'ID' is the primary key, and is an auto numbered identity field... > >
Don't see what you're looking for? Try a search.
|