Home All Groups Group Topic Archive Search About

Getting double count of updated records

Author
31 Jan 2007 6:36 PM
David
I have an SQL statement that uses the Command method ExecuteNonQuery and it
is returning twice the number of rows (24) actually updated.  When I run the
same statement using SQL SELECT I get 12 rows.  Below is my ASP.NET SQL
code:

strSQL = "UPDATE File_Mst" & _

" SET CheckedOut = 12345"  & _

" WHERE ([BoxNum] Like N'%41644%')" & _

" AND ([CheckedOut] = 0)"


cmdSelect = New SqlCommand(strSQL, conFileData)

intRecsProcessed = cmdSelect.ExecuteNonQuery()

The variable intRecsProcessed is returning a count of 24 but only 12 rows
are affected.  Can someone help with this?  Thank you.

David

Author
31 Jan 2007 8:21 PM
David
I think I found out why.  I have an update trigger on the table that updates
another field on that same table.  Does this affect the returned count?
Thanks.

David

Show quote
"David" <dlch***@lifetimeinc.com> wrote in message
news:OyelTbWRHHA.1000@TK2MSFTNGP05.phx.gbl...
>I have an SQL statement that uses the Command method ExecuteNonQuery and it
>is returning twice the number of rows (24) actually updated.  When I run
>the same statement using SQL SELECT I get 12 rows.  Below is my ASP.NET SQL
>code:
>
> strSQL = "UPDATE File_Mst" & _
>
> " SET CheckedOut = 12345"  & _
>
> " WHERE ([BoxNum] Like N'%41644%')" & _
>
> " AND ([CheckedOut] = 0)"
>
>
> cmdSelect = New SqlCommand(strSQL, conFileData)
>
> intRecsProcessed = cmdSelect.ExecuteNonQuery()
>
> The variable intRecsProcessed is returning a count of 24 but only 12 rows
> are affected.  Can someone help with this?  Thank you.
>
> David
>
Author
31 Jan 2007 11:01 PM
RobinS
Yes. If you add "SET NOCOUNT ON" for the update trigger's procedure, I
think it will then *not* return those updated rows in your rowcount.

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
-------------------------------
Show quote
"David" <dlch***@lifetimeinc.com> wrote in message
news:uf39oVXRHHA.3440@TK2MSFTNGP03.phx.gbl...
>I think I found out why.  I have an update trigger on the table that
>updates another field on that same table.  Does this affect the returned
>count? Thanks.
>
> David
>
> "David" <dlch***@lifetimeinc.com> wrote in message
> news:OyelTbWRHHA.1000@TK2MSFTNGP05.phx.gbl...
>>I have an SQL statement that uses the Command method ExecuteNonQuery and
>>it is returning twice the number of rows (24) actually updated.  When I
>>run the same statement using SQL SELECT I get 12 rows.  Below is my
>>ASP.NET SQL code:
>>
>> strSQL = "UPDATE File_Mst" & _
>>
>> " SET CheckedOut = 12345"  & _
>>
>> " WHERE ([BoxNum] Like N'%41644%')" & _
>>
>> " AND ([CheckedOut] = 0)"
>>
>>
>> cmdSelect = New SqlCommand(strSQL, conFileData)
>>
>> intRecsProcessed = cmdSelect.ExecuteNonQuery()
>>
>> The variable intRecsProcessed is returning a count of 24 but only 12
>> rows are affected.  Can someone help with this?  Thank you.
>>
>> David
>>
>
>
Author
1 Feb 2007 2:24 PM
David
Thanks.  I'll try that.  That makes sense.

David

Show quote
"RobinS" <RobinS@NoSpam.yah.none> wrote in message
news:NeednVBqNoosglzYnZ2dnUVZ_vqpnZ2d@comcast.com...
> Yes. If you add "SET NOCOUNT ON" for the update trigger's procedure, I
> think it will then *not* return those updated rows in your rowcount.
>
> Robin S.
> Ts'i mahnu uterna ot twan ot geifur hingts uto.
> -------------------------------
> "David" <dlch***@lifetimeinc.com> wrote in message
> news:uf39oVXRHHA.3440@TK2MSFTNGP03.phx.gbl...
>>I think I found out why.  I have an update trigger on the table that
>>updates another field on that same table.  Does this affect the returned
>>count? Thanks.
>>
>> David
>>
>> "David" <dlch***@lifetimeinc.com> wrote in message
>> news:OyelTbWRHHA.1000@TK2MSFTNGP05.phx.gbl...
>>>I have an SQL statement that uses the Command method ExecuteNonQuery and
>>>it is returning twice the number of rows (24) actually updated.  When I
>>>run the same statement using SQL SELECT I get 12 rows.  Below is my
>>>ASP.NET SQL code:
>>>
>>> strSQL = "UPDATE File_Mst" & _
>>>
>>> " SET CheckedOut = 12345"  & _
>>>
>>> " WHERE ([BoxNum] Like N'%41644%')" & _
>>>
>>> " AND ([CheckedOut] = 0)"
>>>
>>>
>>> cmdSelect = New SqlCommand(strSQL, conFileData)
>>>
>>> intRecsProcessed = cmdSelect.ExecuteNonQuery()
>>>
>>> The variable intRecsProcessed is returning a count of 24 but only 12
>>> rows are affected.  Can someone help with this?  Thank you.
>>>
>>> David
>>>
>>
>>
>
>

AddThis Social Bookmark Button