473,388 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

One record returned but e.AffectedRows == 0?

Stored Procedure:

CREATE PROCEDURE [dbo].[GetBanner]

@BannerPage nvarchar(50),
@MagazineID int
AS
BEGIN
SET NOCOUNT ON;

DECLARE @BannerID int
SELECT TOP 1
@BannerID = BannerID
FROM Banners
WHERE BannerPage=@BannerPage AND MagazineID = @MagazineID
AND StartDate <= GetDate() AND EndDate >=GetDate()
ORDER BY Views

SELECT
BannerID,
BannerFileName,
AltText,
URL,
Views
FROM Banners
WHERE BannerID = @BannerID

UPDATE Banners SET Views = Views +1 WHERE BannerID = @BannerID
UPDATE BannerStats SET Views = Views + 1 WHERE BannerID = @BannerID
END

OnSelected method:

protected void dsBanner_Selected(object sender,
SqlDataSourceStatusEventArgs e)
{
int RecordCount = e.AffectedRows;
Response.Write(RecordCount);
}
This ALWAYS gives me 0 - despite the fact that the correct banner is pulled
from the database, and updated etc. Also, when I execute the procedure (for
valid parameter values) in SSMS, I get "1 row(s) Affected". Can anyone tell
me what I need to change to get the proper value?

Thanks
Jan 9 '07 #1
3 4306
GD
AffectedRows refers to the number of rows affected by the last SQL statement
to be executed. Therefore it would appear that the line
UPDATE BannerStats SET Views = Views + 1 WHERE BannerID = @BannerID does not
affect any rows, even though a record is returned from the SELECT statement
previous to it.

So the solution would be to move the two update statements to be above the
SELECT and execute them based on @@ROWCOUNT=1 from your SELECT TOP
statement.

Gary

"Mike" <xx*@xxx.xxxwrote in message
news:Oc**************@TK2MSFTNGP06.phx.gbl...
Stored Procedure:

CREATE PROCEDURE [dbo].[GetBanner]

@BannerPage nvarchar(50),
@MagazineID int
AS
BEGIN
SET NOCOUNT ON;

DECLARE @BannerID int
SELECT TOP 1
@BannerID = BannerID
FROM Banners
WHERE BannerPage=@BannerPage AND MagazineID = @MagazineID
AND StartDate <= GetDate() AND EndDate >=GetDate()
ORDER BY Views

SELECT
BannerID,
BannerFileName,
AltText,
URL,
Views
FROM Banners
WHERE BannerID = @BannerID

UPDATE Banners SET Views = Views +1 WHERE BannerID = @BannerID
UPDATE BannerStats SET Views = Views + 1 WHERE BannerID = @BannerID
END

OnSelected method:

protected void dsBanner_Selected(object sender,
SqlDataSourceStatusEventArgs e)
{
int RecordCount = e.AffectedRows;
Response.Write(RecordCount);
}
This ALWAYS gives me 0 - despite the fact that the correct banner is
pulled
from the database, and updated etc. Also, when I execute the procedure
(for
valid parameter values) in SSMS, I get "1 row(s) Affected". Can anyone
tell
me what I need to change to get the proper value?

Thanks


Jan 9 '07 #2
Thanks, but it still give me an AffectedRows of 0.

Mike

"GD" <No*****************************@eircom.net.NoSpam wrote in message
news:O2**************@TK2MSFTNGP02.phx.gbl...
AffectedRows refers to the number of rows affected by the last SQL
statement
to be executed. Therefore it would appear that the line
UPDATE BannerStats SET Views = Views + 1 WHERE BannerID = @BannerID does
not
affect any rows, even though a record is returned from the SELECT
statement
previous to it.

So the solution would be to move the two update statements to be above the
SELECT and execute them based on @@ROWCOUNT=1 from your SELECT TOP
statement.

Gary

"Mike" <xx*@xxx.xxxwrote in message
news:Oc**************@TK2MSFTNGP06.phx.gbl...
>Stored Procedure:

CREATE PROCEDURE [dbo].[GetBanner]

@BannerPage nvarchar(50),
@MagazineID int
AS
BEGIN
SET NOCOUNT ON;

DECLARE @BannerID int
SELECT TOP 1
@BannerID = BannerID
FROM Banners
WHERE BannerPage=@BannerPage AND MagazineID = @MagazineID
AND StartDate <= GetDate() AND EndDate >=GetDate()
ORDER BY Views

SELECT
BannerID,
BannerFileName,
AltText,
URL,
Views
FROM Banners
WHERE BannerID = @BannerID

UPDATE Banners SET Views = Views +1 WHERE BannerID = @BannerID
UPDATE BannerStats SET Views = Views + 1 WHERE BannerID = @BannerID
END

OnSelected method:

protected void dsBanner_Selected(object sender,
SqlDataSourceStatusEventArgs e)
{
int RecordCount = e.AffectedRows;
Response.Write(RecordCount);
}
This ALWAYS gives me 0 - despite the fact that the correct banner is
pulled
>from the database, and updated etc. Also, when I execute the procedure
(for
>valid parameter values) in SSMS, I get "1 row(s) Affected". Can anyone
tell
>me what I need to change to get the proper value?

Thanks



Jan 10 '07 #3
Oh. Just found out what the problem is. Looking at the AffectedRows
documentation here:
http://msdn2.microsoft.com/en-us/lib...ectedrows.aspx, I
find this useful snippet:
"All operations return the number of rows affected by the operation. The
AffectedRows property has the same value as the return value of the Update,
Insert, and Delete methods.

When the Select method is called and the data source is set to DataReader
mode, the return value is 0 in all cases. "

I am using a DataReader. Now I think about this, of course it's logical.
DataReader only supports a forward-only cursor. It can't go through the
recordset to get a total, then go back to the beginning to process the data.

Mike
"Mike" <in*****@newsgroups.comwrote in message
news:Oz**************@TK2MSFTNGP06.phx.gbl...
Thanks, but it still give me an AffectedRows of 0.

Mike

"GD" <No*****************************@eircom.net.NoSpam wrote in message
news:O2**************@TK2MSFTNGP02.phx.gbl...
>AffectedRows refers to the number of rows affected by the last SQL
statement
to be executed. Therefore it would appear that the line
UPDATE BannerStats SET Views = Views + 1 WHERE BannerID = @BannerID does
not
affect any rows, even though a record is returned from the SELECT
statement
previous to it.

So the solution would be to move the two update statements to be above
the
SELECT and execute them based on @@ROWCOUNT=1 from your SELECT TOP
statement.

Gary

"Mike" <xx*@xxx.xxxwrote in message
news:Oc**************@TK2MSFTNGP06.phx.gbl...
>>Stored Procedure:

CREATE PROCEDURE [dbo].[GetBanner]

@BannerPage nvarchar(50),
@MagazineID int
AS
BEGIN
SET NOCOUNT ON;

DECLARE @BannerID int
SELECT TOP 1
@BannerID = BannerID
FROM Banners
WHERE BannerPage=@BannerPage AND MagazineID = @MagazineID
AND StartDate <= GetDate() AND EndDate >=GetDate()
ORDER BY Views

SELECT
BannerID,
BannerFileName,
AltText,
URL,
Views
FROM Banners
WHERE BannerID = @BannerID

UPDATE Banners SET Views = Views +1 WHERE BannerID = @BannerID
UPDATE BannerStats SET Views = Views + 1 WHERE BannerID = @BannerID
END

OnSelected method:

protected void dsBanner_Selected(object sender,
SqlDataSourceStatusEventArgs e)
{
int RecordCount = e.AffectedRows;
Response.Write(RecordCount);
}
This ALWAYS gives me 0 - despite the fact that the correct banner is
pulled
>>from the database, and updated etc. Also, when I execute the procedure
(for
>>valid parameter values) in SSMS, I get "1 row(s) Affected". Can anyone
tell
>>me what I need to change to get the proper value?

Thanks




Jan 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Mark | last post by:
I have a working PHP/MySQL application used for data entry. The data entry screen includes a "Save" button. The PHP code for this button looks like this: if (isset($_POST)) { if ($_POST ==...
5
by: Andrew | last post by:
Hi All, Have come across something weird and am after some help. Say i run this query where rec_id is a column of table arlhrl, select * from arlhrl where rec_id >= 14260 This returns to...
8
by: mark | last post by:
Access2000 How do I write a query that combines the CTC field from each record below into one record? I need to concatenate the CTC field with a separator, like below: ...
17
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset...
6
by: Mike Conklin | last post by:
This one really has me going. Probably something silly. I'm using dcount for a report to determine the number of different types of tests proctored in a semester. My report is based on a...
30
by: S. van Beek | last post by:
Dear reader A record set can be empty because the condition in the query delivers no records. Is there a VBA code to check the status of a record set, record set empty
2
by: | last post by:
Hello Everyone, I am using VB and ASP.Net to build a web application with VS.2005. I have a SqlDataSource defined and am using it to populate a table . Is there an easy way to determine the...
7
by: rfinch | last post by:
Very new to this but using the MS working with dynamics CRM 3.0 book to run web application to retrieve lead records from CRM 3.0. Have followed the book instructions on page 380-382. But am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.