Showing posts with label total. Show all posts
Showing posts with label total. Show all posts

Monday, March 12, 2012

Paging query

I have created a stored proc for paging on a datalist which uses a objectDataSource.

I have a output param itemCount which should return the total rows. Them I am creating a temp table to fetch the records for each page request. My output param works fine if I comment out all the other select statements. But returns null with them. Any help would be appreciated.

CREATE PROCEDURE [dbo].[CMRC_PRODUCTS_GetListByCategory]
(
@.categoryID int,
@.pageIndex INT,
@.numRows INT,
@.itemCount INT OUTPUT

)
AS

SELECT @.itemCount= COUNT(*) FROM CMRC_Products whereCMRC_Products.CategoryID=@.categoryID

Declare @.startRowIndex INT;
Declare @.finishRowIndex INT;
set @.startRowIndex = ((@.pageIndex -1) * @.numRows) + 1;
set @.finishRowIndex = @.pageIndex * @.numRows

DECLARE @.tCat TABLE (TID int identity(1,1),ProductID int, CategoryID int, SellerUserName varchar(100), ModelName varchar(100), Medium varchar(50),
ProductImage varchar(100),UnitCost money,Description varchar(1500), CategoryName varchar(100), isActive bit,weight money)

INSERT INTO @.tCat(ProductID, CategoryID,SellerUserName,ModelName,Medium,ProductImage,UnitCost,Description,CategoryName, isActive,weight)
SELECT CMRC_Products.ProductID, CMRC_Products.CategoryID, CMRC_Products.SellerUserName, CMRC_Products.ModelName, CMRC_Products.Medium,CMRC_Products.ProductImage,
CMRC_Products.UnitCost, CMRC_Products.Description, CMRC_Categories.CategoryName, CMRC_Products.isActive,CMRC_Products.weight
FROM CMRC_Products INNER JOIN
CMRC_Categories ON CMRC_Products.CategoryID = CMRC_Categories.CategoryID
WHERE (CMRC_Products.CategoryID = @.categoryID) AND (CMRC_Products.isActive = 1)

SELECT ProductID, CategoryID,SellerUserName,ModelName,Medium,ProductImage,UnitCost,Description,CategoryName, isActive,weight
FROM @.tCat
WHERE TID >= @.startRowIndex AND TID <= @.finishRowIndex
GO

spawned:

My output param works fine if I comment out all the other select statements. But returns null with them.

Strange! Other select statements should not effect the output param as non of them refereneces the output param. How did you get the output param's value after executing the sp? Will the output param work fine if you directly execute the stored procedure in SQL via Query Analyzer (or Management Studio) without commenting out some statements?

|||

You are correct, I tested in Query Analyser and the Output was returned OK.

The issue was that the method was returning a DataReader along with a output param. The two don't get along! You have to close the DataReader before the output param is visible. This is 'by design' accourding to MS.http://support.microsoft.com/?id=308051 (See resolution section). Moving to the end of the recordset didn't seem to work but close it does.

This was a real pain as I had to change the method to Read the data into a list<Product> then close the Reader, then set reference to my output param.

Anyway all done now and works a treat. Thanks for you advice.

|||

Then how about returning the count as a result set instead of putting it in the output parameter? I mean you can write your stored procedure this way:

CREATE PROCEDURE [dbo].[CMRC_PRODUCTS_GetListByCategory]
(
@.categoryID int,
@.pageIndex INT,
@.numRows INT,
)
AS

SELECT COUNT(*) FROM CMRC_Products whereCMRC_Products.CategoryID=@.categoryID

//do other things

go

And then in the code you can get the count from the first result set using SqlDataReader.

|||

Ok, I thought only DataSets alowed that (ie Tables[0], Table[1] etc, or does the Reader just return it at the end of the recordset.

I'll have a play around with it. Thanks for the tip.

Cheers,Shaun.

|||

I am having exa ctly the same problem.

You mentioned that you used a method to Read the data into a list<Product> then close the Reader, then set reference to my output param. This is exactly what i am trying to do now could you tell me the code for this.

many thanks

martin

|||

In my Product.cs I have the following new method:

//Used for paged results in catagory searchpublicvoid ProductList(int ProductID,string Medium,string ModelName,string ProductImage,double UnitCost,bool IsAdult)

{

_ProductID = ProductID;

_Medium = Medium;

_ModelName = ModelName;

_ProductImage = ProductImage;

_UnitCost = UnitCost;

_IsAdult = IsAdult;

}

***************************

In my CatalogManager .cs (I didn't put it in the provider project as it is a pain in the ar*e to maintain) I have the following:

public

staticList <Product> GetProductsByCategoryPaging(int categoryID,int pageIndex,int numRows,outint itemCount)

{

using (SqlConnection connection =newSqlConnection(ConfigurationManager.ConnectionStrings["CommerceTemplate"].ConnectionString))

{

using (SqlCommand command =newSqlCommand("CMRC_PRODUCTS_GetListByCategoryPaging", connection))

{

command.CommandType =

CommandType.StoredProcedure;

command.Parameters.Add(

"@.itemCount",SqlDbType.Int, 4);

command.Parameters[

"@.itemCount"].Direction =ParameterDirection.Output;

command.Parameters.Add(

newSqlParameter("@.categoryID", categoryID));

command.Parameters.Add(

newSqlParameter("@.pageIndex", pageIndex));

command.Parameters.Add(

newSqlParameter("@.numRows", numRows));

connection.Open();

//populate listList<Product> list =newList<Product>();using (SqlDataReader rdr = command.ExecuteReader()) {while (rdr.Read()) {Product temp =newProduct();

temp.ProductList(

(

int)rdr["ProductID"],

rdr[

"Medium"].ToString(),

rdr[

"ModelName"].ToString(),

rdr[

"ProductImage"].ToString(),Convert.ToDouble (rdr["UnitCost"]),

(

bool)rdr["IsAdult"]);

list.Add(temp);

}

rdr.Close();

}

itemCount = (

int)command.Parameters["@.itemCount"].Value;return list;

}

}

}

You'll need to include the this declaration in the CatalogManager:

using System.Collections.Generic;

Good luck I feel you pain :-)

|||

really, many thanks for that it was driving me crazy

cheers

martin

|||

Once again many thanks for your help with this. Everhting is working fine.

Just one question did you use querystrings and if you did, how did you validate

them. I am having a lot of problems trying to figure out how to do this.

many thanks for all your help

martin

|||

Yes I did use query strings. My catalog page handles many queries.

I had a switch statement in the Page Load.

switch (SearchType) <== I have a param for query type.

{

case"c"://category search

cid =

Convert.ToInt32(Request.QueryString["cid"]);

dlCatalog.DataSource = objDSCategory;

dlCatalog.DataBind();

break;case"a"://artist search

dlCatalog.DataSource = objDSArtist;

dlCatalog.DataBind();

break;

etc

}

in the obj DataSource in aspx:

<

asp:ObjectDataSourceID="objDSGallery"runat="server"OldValuesParameterFormatString="{0}"SelectMethod="GetProductsByGalleryPaging"TypeName="CatalogManager"OnSelected="objDSGallery_Selected"OnSelecting="objDSGallery_Selecting"><SelectParameters><asp:QueryStringParameterName="GalleryID"QueryStringField="gid"Type="Int32"/><asp:QueryStringParameterName="pageIndex"QueryStringField="PageIndex"DefaultValue="0"/><asp:QueryStringParameterName="numRows"QueryStringField="NumRows"DefaultValue="6"/><asp:ParameterName="itemCount"Direction="Output"Type="Int32"/></SelectParameters></asp:ObjectDataSource>

Let me know if you have any more dramas, I can email you the code I'm using for reference.

The OnSelected and Selecting methods are used for updating the paging links.

I can email you the code if you like.

Cheers,Shaun.

|||

thanks for your reply

i would be grateful for the code my address istbcmartingharvey@.yahoo.co.jp

many thanks

martin

|||

Is your Yahoo account still active? got a return reply saying:

554 delivery error: dd This user doesn't have a yahoo.co.jp account (tbcmartingharvey@.yahoo.co.jp)

Is that your correct mail address?

Cheers,Shaun

ps I'll be away for several days (biz not pleasure :-( ) so will not get the code to you till Tues. Probably best I provide it as a download from my server so other users can access it too.

|||

thanks for your reply shaun

must be the summer heat

itstbcmartinharvey@.yahoo.co.jp

thank you

martin

Friday, March 9, 2012

Pagination of data

Hi
I am developing a vb2005/sql server 2005 winform app which involves
displaying records in a list, one page at a time. The total number of
records is large. I am wondering if there is a way either in vb/ado or sql
server that automatically pages a certain number of records at a time and
when user scrolls down (or up) pages the next set of records? I guess I can
possibly program it manually but it may be complicated specially when the
records in the next/previous set are different due to the different sort
orders. Ideally I am looking for giving a select statement to include all
records as data source and then expect system to handle any pagination and
bringing only one page of record from server at any one time.
Thanks
RegardsTake a look at this article.
http://www.aspfaq.com/show.asp?id=2120
David Portas
SQL Server MVP
--|||I am doing it for a winform app and asp may not be relevant but I will have
a look.
Thanks
Regards
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:IZidne6mqKZJLJreRVn-ow@.giganews.com...
> Take a look at this article.
> http://www.aspfaq.com/show.asp?id=2120
> --
> David Portas
> SQL Server MVP
> --
>|||Of the various solutions given, most of them are not ASP-specific. Mostly
they use TSQL.
David Portas
SQL Server MVP
--|||Hi John,
I am not a DBA or even half-experienced db developer but, I guess you could
consider achieving your goal by using views. You will still, as you state,
return the whole recordset and possibly 'store it' as a dataset. You can
then create the required views as needed. If there are any DBA's reading
PLEASE don't lecture on the bad practice of returning more records than
required...IT'S NOT MY IDEA! :-) :-)
I know you asked if there was a way to do this 'automatically', but I don't
know of one, other than the built-in methods within the asp datagrid. Sorry
if this is not helpful.
Good luck.
Phil
"John" <John@.nospam.infovis.co.uk> wrote in message
news:eWQ3DddpFHA.2976@.TK2MSFTNGP12.phx.gbl...
> Hi
> I am developing a vb2005/sql server 2005 winform app which involves
> displaying records in a list, one page at a time. The total number of
> records is large. I am wondering if there is a way either in vb/ado or sql
> server that automatically pages a certain number of records at a time and
> when user scrolls down (or up) pages the next set of records? I guess I
> can possibly program it manually but it may be complicated specially when
> the records in the next/previous set are different due to the different
> sort orders. Ideally I am looking for giving a select statement to include
> all records as data source and then expect system to handle any pagination
> and bringing only one page of record from server at any one time.
> Thanks
> Regards
>|||Check out:
http://www.aspfaq.com/show.asp?id=2120
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Phil G." <Phil@.nospam.com> wrote in message
news:de9hlf$9fl$1@.nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
Hi John,
I am not a DBA or even half-experienced db developer but, I guess you could
consider achieving your goal by using views. You will still, as you state,
return the whole recordset and possibly 'store it' as a dataset. You can
then create the required views as needed. If there are any DBA's reading
PLEASE don't lecture on the bad practice of returning more records than
required...IT'S NOT MY IDEA! :-) :-)
I know you asked if there was a way to do this 'automatically', but I don't
know of one, other than the built-in methods within the asp datagrid. Sorry
if this is not helpful.
Good luck.
Phil
"John" <John@.nospam.infovis.co.uk> wrote in message
news:eWQ3DddpFHA.2976@.TK2MSFTNGP12.phx.gbl...
> Hi
> I am developing a vb2005/sql server 2005 winform app which involves
> displaying records in a list, one page at a time. The total number of
> records is large. I am wondering if there is a way either in vb/ado or sql
> server that automatically pages a certain number of records at a time and
> when user scrolls down (or up) pages the next set of records? I guess I
> can possibly program it manually but it may be complicated specially when
> the records in the next/previous set are different due to the different
> sort orders. Ideally I am looking for giving a select statement to include
> all records as data source and then expect system to handle any pagination
> and bringing only one page of record from server at any one time.
> Thanks
> Regards
>

Pagination of data

Hi
I am developing a vb2005/sql server 2005 winform app which involves
displaying records in a list, one page at a time. The total number of
records is large. I am wondering if there is a way either in vb/ado or sql
server that automatically pages a certain number of records at a time and
when user scrolls down (or up) pages the next set of records? I guess I can
possibly program it manually but it may be complicated specially when the
records in the next/previous set are different due to the different sort
orders. Ideally I am looking for giving a select statement to include all
records as data source and then expect system to handle any pagination and
bringing only one page of record from server at any one time.
Thanks
RegardsTake a look at this article.
http://www.aspfaq.com/show.asp?id=2120
--
David Portas
SQL Server MVP
--|||I am doing it for a winform app and asp may not be relevant but I will have
a look.
Thanks
Regards
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:IZidne6mqKZJLJreRVn-ow@.giganews.com...
> Take a look at this article.
> http://www.aspfaq.com/show.asp?id=2120
> --
> David Portas
> SQL Server MVP
> --
>|||Of the various solutions given, most of them are not ASP-specific. Mostly
they use TSQL.
--
David Portas
SQL Server MVP
--|||Hi John,
I am not a DBA or even half-experienced db developer but, I guess you could
consider achieving your goal by using views. You will still, as you state,
return the whole recordset and possibly 'store it' as a dataset. You can
then create the required views as needed. If there are any DBA's reading
PLEASE don't lecture on the bad practice of returning more records than
required...IT'S NOT MY IDEA! :-) :-)
I know you asked if there was a way to do this 'automatically', but I don't
know of one, other than the built-in methods within the asp datagrid. Sorry
if this is not helpful.
Good luck.
Phil
"John" <John@.nospam.infovis.co.uk> wrote in message
news:eWQ3DddpFHA.2976@.TK2MSFTNGP12.phx.gbl...
> Hi
> I am developing a vb2005/sql server 2005 winform app which involves
> displaying records in a list, one page at a time. The total number of
> records is large. I am wondering if there is a way either in vb/ado or sql
> server that automatically pages a certain number of records at a time and
> when user scrolls down (or up) pages the next set of records? I guess I
> can possibly program it manually but it may be complicated specially when
> the records in the next/previous set are different due to the different
> sort orders. Ideally I am looking for giving a select statement to include
> all records as data source and then expect system to handle any pagination
> and bringing only one page of record from server at any one time.
> Thanks
> Regards
>|||Check out:
http://www.aspfaq.com/show.asp?id=2120
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Phil G." <Phil@.nospam.com> wrote in message
news:de9hlf$9fl$1@.nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
Hi John,
I am not a DBA or even half-experienced db developer but, I guess you could
consider achieving your goal by using views. You will still, as you state,
return the whole recordset and possibly 'store it' as a dataset. You can
then create the required views as needed. If there are any DBA's reading
PLEASE don't lecture on the bad practice of returning more records than
required...IT'S NOT MY IDEA! :-) :-)
I know you asked if there was a way to do this 'automatically', but I don't
know of one, other than the built-in methods within the asp datagrid. Sorry
if this is not helpful.
Good luck.
Phil
"John" <John@.nospam.infovis.co.uk> wrote in message
news:eWQ3DddpFHA.2976@.TK2MSFTNGP12.phx.gbl...
> Hi
> I am developing a vb2005/sql server 2005 winform app which involves
> displaying records in a list, one page at a time. The total number of
> records is large. I am wondering if there is a way either in vb/ado or sql
> server that automatically pages a certain number of records at a time and
> when user scrolls down (or up) pages the next set of records? I guess I
> can possibly program it manually but it may be complicated specially when
> the records in the next/previous set are different due to the different
> sort orders. Ideally I am looking for giving a select statement to include
> all records as data source and then expect system to handle any pagination
> and bringing only one page of record from server at any one time.
> Thanks
> Regards
>

Pagination of data

Hi
I am developing a vb2005/sql server 2005 winform app which involves
displaying records in a list, one page at a time. The total number of
records is large. I am wondering if there is a way either in vb/ado or sql
server that automatically pages a certain number of records at a time and
when user scrolls down (or up) pages the next set of records? I guess I can
possibly program it manually but it may be complicated specially when the
records in the next/previous set are different due to the different sort
orders. Ideally I am looking for giving a select statement to include all
records as data source and then expect system to handle any pagination and
bringing only one page of record from server at any one time.
Thanks
Regards
Take a look at this article.
http://www.aspfaq.com/show.asp?id=2120
David Portas
SQL Server MVP
|||I am doing it for a winform app and asp may not be relevant but I will have
a look.
Thanks
Regards
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:IZidne6mqKZJLJreRVn-ow@.giganews.com...
> Take a look at this article.
> http://www.aspfaq.com/show.asp?id=2120
> --
> David Portas
> SQL Server MVP
> --
>
|||Of the various solutions given, most of them are not ASP-specific. Mostly
they use TSQL.
David Portas
SQL Server MVP
|||Hi John,
I am not a DBA or even half-experienced db developer but, I guess you could
consider achieving your goal by using views. You will still, as you state,
return the whole recordset and possibly 'store it' as a dataset. You can
then create the required views as needed. If there are any DBA's reading
PLEASE don't lecture on the bad practice of returning more records than
required...IT'S NOT MY IDEA! :-) :-)
I know you asked if there was a way to do this 'automatically', but I don't
know of one, other than the built-in methods within the asp datagrid. Sorry
if this is not helpful.
Good luck.
Phil
"John" <John@.nospam.infovis.co.uk> wrote in message
news:eWQ3DddpFHA.2976@.TK2MSFTNGP12.phx.gbl...
> Hi
> I am developing a vb2005/sql server 2005 winform app which involves
> displaying records in a list, one page at a time. The total number of
> records is large. I am wondering if there is a way either in vb/ado or sql
> server that automatically pages a certain number of records at a time and
> when user scrolls down (or up) pages the next set of records? I guess I
> can possibly program it manually but it may be complicated specially when
> the records in the next/previous set are different due to the different
> sort orders. Ideally I am looking for giving a select statement to include
> all records as data source and then expect system to handle any pagination
> and bringing only one page of record from server at any one time.
> Thanks
> Regards
>
|||Check out:
http://www.aspfaq.com/show.asp?id=2120
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
"Phil G." <Phil@.nospam.com> wrote in message
news:de9hlf$9fl$1@.nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
Hi John,
I am not a DBA or even half-experienced db developer but, I guess you could
consider achieving your goal by using views. You will still, as you state,
return the whole recordset and possibly 'store it' as a dataset. You can
then create the required views as needed. If there are any DBA's reading
PLEASE don't lecture on the bad practice of returning more records than
required...IT'S NOT MY IDEA! :-) :-)
I know you asked if there was a way to do this 'automatically', but I don't
know of one, other than the built-in methods within the asp datagrid. Sorry
if this is not helpful.
Good luck.
Phil
"John" <John@.nospam.infovis.co.uk> wrote in message
news:eWQ3DddpFHA.2976@.TK2MSFTNGP12.phx.gbl...
> Hi
> I am developing a vb2005/sql server 2005 winform app which involves
> displaying records in a list, one page at a time. The total number of
> records is large. I am wondering if there is a way either in vb/ado or sql
> server that automatically pages a certain number of records at a time and
> when user scrolls down (or up) pages the next set of records? I guess I
> can possibly program it manually but it may be complicated specially when
> the records in the next/previous set are different due to the different
> sort orders. Ideally I am looking for giving a select statement to include
> all records as data source and then expect system to handle any pagination
> and bringing only one page of record from server at any one time.
> Thanks
> Regards
>

Saturday, February 25, 2012

Page Subtotals (Not Cumulative)

Hello,

I want to display subtotals for a column only for that page. Like;

Index Value

--

1 4

2 5

Subtotal 9

-

3 1

4 2

Subtotal 3

Total 12

RunningValue gives cumulative totals. I need subtotals for each visible page only. Is there a way to do it ?

Constraints:

I'm using a table. And I shouldn't use page breaks on my report.

Thanks in advance

Insert/ Add the Page Footer to the report. Now, inser another text box and the expression for this will be

=Sum(ReportItems!textbox6.Value)

TextBox6 is the field which contains the value, More information about this can be found at

http://technet.microsoft.com/en-us/library/ms159677.aspx

|||Thank you for your reply, Techquest.

It is solution for what I asked. But I need something different. I shouldn't use page footer or header either. I'm limited with the page body.

Monday, February 20, 2012

page number & records number

1. how to show page number & total page number in report body?

2. how to show total records number?

For #1: Create a text box. For the value, enter the following:

="Page " + Globals!PageNumber.ToString() + " of " + Globals!TotalPages.ToString()

For #2: If you just want to show the number of rows in a table for example, then create a text box, and enter the following:

=CountRows(Fields!FieldName.Value)

|||

thanks for reply, but errors found.

for #1:

[rsPageNumberInBody] The Value expression for the textbox ‘textbox1’ refers to the global variable PageNumber or TotalPages. These global variables can be used only in the page header and page footer.

for #2:

[rsInvalidAggregateScope] The Value expression for the textbox ‘textbox2’ has a scope parameter that is not valid for an aggregate function. The scope parameter must be set to a string constant that is equal to either the name of a containing group, the name of a containing data region, or the name of a data set.

pls advise, thanks

|||

for #1: I can't think of another way to output the page numbers, so you might have to just use the header and footer to handle it.

for #2: Create a text box and enter the value: =CountRows("DataSetName")

This will output the number of rows returned by the dataset.

|||for #2 is work. thanks.|||

Okay, I found a solution for #1:

Go to "Report" -> "Report Properties" -> "Code"

In the Custom Code section, enter the following:

Public Funtion PageNumber() as String
Dim str as String
str = Me.Report.Globals!PageNumber.ToString()
Return str
End Function

Public Function TotalPages() as String
Dim str as String
str = Me.Report.Globals!TotalPages.ToString()
Return str
End Function


Now you will be able to access these functions anywhere in the report (header, body, or footer). So, to output the page number and total pages in a textbox located in the body simply enter this for the value:

="Page " + Code.PageNumber() + " of " + Code.TotalPages()

|||I cannot get this to work. I get an end of statement expected error for the first line. I copied the code into report, report properties, code tab and change the function names to suit my naming convention. Also, when I try to refer to the functions in a textbox Code.FunctionName does not recognize the function in the custom code section.|||

Okay, I found the error. When I typed in the code for the post, I spelled "Function" incorrectly on the very first line... Just add the missing "c" and you will be good to go. Sorry about that.
Joel

|||

ah, it's okay... I don't know why I didn't notice that. I got the code in without any errors this time. When I test it, it doesn't seem to function as desired.

= Code.FunctionName()

I only get the number 1 in all the textboxes that carry the above information.

|||

Can you copy and paste your custom code as well as your expression for the textbox?

Thanks,
Joel

|||

Custom Code

Public Function PageNumber()
Dim str as String
str = me.Report.Globals!PageNumber.ToString()
Return str
End Function

Public Function TotalPages()
Dim str as String
str = me.Report.Globals!TotalPages.ToString()
Return str
End Function

in Text Boxes in Tables

=Code.PageNumber() & " " & Code.TotalPages()

I'm running VS2k5 & SSRS2k5. My report has two columns, and runs about 200 pages. I have two tables, and I'm trying this in both tables in group headers and detail lines. All I get for all the text boxes is "1 1". I hope this information helps. I know I specified earlier that I changed the function names for our naming conventions, but I decided to go with exactly what you have until I can get it to work, then I'll make any necessary changes.

Thanks!

Curtis

|||

Hmm, I'm also getting the same results. I think it's safe to say I didn't test this very well. When I first wrote the function, I tested it on a report with only one page and when it outputed "Page 1 of 1", I figured it was good to go. However, after playing around with a report that is 3 pages, it's clear this function is not going to work.

I'm not really sure why we are only getting the value 1 for both globals. It is clearly accessing these globals because if you change their names it will create an error saying they are not members of "Globals". Anyway since that didn't work, I really can't think of another idea on how to output page # and total pages in the body. If you come up with a solution though, I'd be interested to see it.

Thanks,
Joel

|||

I'll see if there is anything I can come up with! If anyone else has any ideas or thoughts, feel free to share! I just do not understand why SSRS should not allow us to use pagenumbering in the data. It doesn't seem to make much sense to me.

Thanks,

Curtis

|||

Okay, so I have a solution that works for me. I do not know if it will be a fix all for everyone interested, but I would like to share anyway. I was talking to our SQL developer about my issues with using page numbering in my data. In my case, I am building a table of contents. He intrigued me when he asked me if I thought about using my SELECT statements to predict my page numbers off of my row numbers. I can use this, because I found in my main report I had to define x number of rows per page to keep multiple detail lines of my table together. What I did in SQL is this:

SELECT

,...

, ROW_NUMBER() OVER (ORDER BY P.PRODLINE, P.PRODCLASS, P.PRODDESC) AS ROWNUMBER

, ((ROW_NUMBER() OVER (ORDER BY P.PRODLINE, P.PRODCLASS, P.PRODDESC)) / 50) + 4 AS PAGENUMBER

...

I determined my table of contents will always be three pages, and I know that I have fifty rows per page. I have run my 200+ page report and compared random sections in my TOC to my report, and I found it was accurate. If there are any questions, please feel free to ask. I would be more than happy to clarify if it is necessary.

|||Thanks for the post. I was thinking about trying something like that myself, good idea.

page number & records number

1. how to show page number & total page number in report body?

2. how to show total records number?

For #1: Create a text box. For the value, enter the following:

="Page " + Globals!PageNumber.ToString() + " of " + Globals!TotalPages.ToString()

For #2: If you just want to show the number of rows in a table for example, then create a text box, and enter the following:

=CountRows(Fields!FieldName.Value)

|||

thanks for reply, but errors found.

for #1:

[rsPageNumberInBody] The Value expression for the textbox ‘textbox1’ refers to the global variable PageNumber or TotalPages. These global variables can be used only in the page header and page footer.

for #2:

[rsInvalidAggregateScope] The Value expression for the textbox ‘textbox2’ has a scope parameter that is not valid for an aggregate function. The scope parameter must be set to a string constant that is equal to either the name of a containing group, the name of a containing data region, or the name of a data set.

pls advise, thanks

|||

for #1: I can't think of another way to output the page numbers, so you might have to just use the header and footer to handle it.

for #2: Create a text box and enter the value: =CountRows("DataSetName")

This will output the number of rows returned by the dataset.

|||for #2 is work. thanks.|||

Okay, I found a solution for #1:

Go to "Report" -> "Report Properties" -> "Code"

In the Custom Code section, enter the following:

Public Funtion PageNumber() as String
Dim str as String
str = Me.Report.Globals!PageNumber.ToString()
Return str
End Function

Public Function TotalPages() as String
Dim str as String
str = Me.Report.Globals!TotalPages.ToString()
Return str
End Function


Now you will be able to access these functions anywhere in the report (header, body, or footer). So, to output the page number and total pages in a textbox located in the body simply enter this for the value:

="Page " + Code.PageNumber() + " of " + Code.TotalPages()

|||I cannot get this to work. I get an end of statement expected error for the first line. I copied the code into report, report properties, code tab and change the function names to suit my naming convention. Also, when I try to refer to the functions in a textbox Code.FunctionName does not recognize the function in the custom code section.|||

Okay, I found the error. When I typed in the code for the post, I spelled "Function" incorrectly on the very first line... Just add the missing "c" and you will be good to go. Sorry about that.
Joel

|||

ah, it's okay... I don't know why I didn't notice that. I got the code in without any errors this time. When I test it, it doesn't seem to function as desired.

= Code.FunctionName()

I only get the number 1 in all the textboxes that carry the above information.

|||

Can you copy and paste your custom code as well as your expression for the textbox?

Thanks,
Joel

|||

Custom Code

Public Function PageNumber()
Dim str as String
str = me.Report.Globals!PageNumber.ToString()
Return str
End Function

Public Function TotalPages()
Dim str as String
str = me.Report.Globals!TotalPages.ToString()
Return str
End Function

in Text Boxes in Tables

=Code.PageNumber() & " " & Code.TotalPages()

I'm running VS2k5 & SSRS2k5. My report has two columns, and runs about 200 pages. I have two tables, and I'm trying this in both tables in group headers and detail lines. All I get for all the text boxes is "1 1". I hope this information helps. I know I specified earlier that I changed the function names for our naming conventions, but I decided to go with exactly what you have until I can get it to work, then I'll make any necessary changes.

Thanks!

Curtis

|||

Hmm, I'm also getting the same results. I think it's safe to say I didn't test this very well. When I first wrote the function, I tested it on a report with only one page and when it outputed "Page 1 of 1", I figured it was good to go. However, after playing around with a report that is 3 pages, it's clear this function is not going to work.

I'm not really sure why we are only getting the value 1 for both globals. It is clearly accessing these globals because if you change their names it will create an error saying they are not members of "Globals". Anyway since that didn't work, I really can't think of another idea on how to output page # and total pages in the body. If you come up with a solution though, I'd be interested to see it.

Thanks,
Joel

|||

I'll see if there is anything I can come up with! If anyone else has any ideas or thoughts, feel free to share! I just do not understand why SSRS should not allow us to use pagenumbering in the data. It doesn't seem to make much sense to me.

Thanks,

Curtis

|||

Okay, so I have a solution that works for me. I do not know if it will be a fix all for everyone interested, but I would like to share anyway. I was talking to our SQL developer about my issues with using page numbering in my data. In my case, I am building a table of contents. He intrigued me when he asked me if I thought about using my SELECT statements to predict my page numbers off of my row numbers. I can use this, because I found in my main report I had to define x number of rows per page to keep multiple detail lines of my table together. What I did in SQL is this:

SELECT

,...

, ROW_NUMBER() OVER (ORDER BY P.PRODLINE, P.PRODCLASS, P.PRODDESC) AS ROWNUMBER

, ((ROW_NUMBER() OVER (ORDER BY P.PRODLINE, P.PRODCLASS, P.PRODDESC)) / 50) + 4 AS PAGENUMBER

...

I determined my table of contents will always be three pages, and I know that I have fifty rows per page. I have run my 200+ page report and compared random sections in my TOC to my report, and I found it was accurate. If there are any questions, please feel free to ask. I would be more than happy to clarify if it is necessary.

|||Thanks for the post. I was thinking about trying something like that myself, good idea.

page number & records number

1. how to show page number & total page number in report body?

2. how to show total records number?

For #1: Create a text box. For the value, enter the following:

="Page " + Globals!PageNumber.ToString() + " of " + Globals!TotalPages.ToString()

For #2: If you just want to show the number of rows in a table for example, then create a text box, and enter the following:

=CountRows(Fields!FieldName.Value)

|||

thanks for reply, but errors found.

for #1:

[rsPageNumberInBody] The Value expression for the textbox ‘textbox1’ refers to the global variable PageNumber or TotalPages. These global variables can be used only in the page header and page footer.

for #2:

[rsInvalidAggregateScope] The Value expression for the textbox ‘textbox2’ has a scope parameter that is not valid for an aggregate function. The scope parameter must be set to a string constant that is equal to either the name of a containing group, the name of a containing data region, or the name of a data set.

pls advise, thanks

|||

for #1: I can't think of another way to output the page numbers, so you might have to just use the header and footer to handle it.

for #2: Create a text box and enter the value: =CountRows("DataSetName")

This will output the number of rows returned by the dataset.

|||for #2 is work. thanks.|||

Okay, I found a solution for #1:

Go to "Report" -> "Report Properties" -> "Code"

In the Custom Code section, enter the following:

Public Funtion PageNumber() as String
Dim str as String
str = Me.Report.Globals!PageNumber.ToString()
Return str
End Function

Public Function TotalPages() as String
Dim str as String
str = Me.Report.Globals!TotalPages.ToString()
Return str
End Function


Now you will be able to access these functions anywhere in the report (header, body, or footer). So, to output the page number and total pages in a textbox located in the body simply enter this for the value:

="Page " + Code.PageNumber() + " of " + Code.TotalPages()

|||I cannot get this to work. I get an end of statement expected error for the first line. I copied the code into report, report properties, code tab and change the function names to suit my naming convention. Also, when I try to refer to the functions in a textbox Code.FunctionName does not recognize the function in the custom code section.|||

Okay, I found the error. When I typed in the code for the post, I spelled "Function" incorrectly on the very first line... Just add the missing "c" and you will be good to go. Sorry about that.
Joel

|||

ah, it's okay... I don't know why I didn't notice that. I got the code in without any errors this time. When I test it, it doesn't seem to function as desired.

= Code.FunctionName()

I only get the number 1 in all the textboxes that carry the above information.

|||

Can you copy and paste your custom code as well as your expression for the textbox?

Thanks,
Joel

|||

Custom Code

Public Function PageNumber()
Dim str as String
str = me.Report.Globals!PageNumber.ToString()
Return str
End Function

Public Function TotalPages()
Dim str as String
str = me.Report.Globals!TotalPages.ToString()
Return str
End Function

in Text Boxes in Tables

=Code.PageNumber() & " " & Code.TotalPages()

I'm running VS2k5 & SSRS2k5. My report has two columns, and runs about 200 pages. I have two tables, and I'm trying this in both tables in group headers and detail lines. All I get for all the text boxes is "1 1". I hope this information helps. I know I specified earlier that I changed the function names for our naming conventions, but I decided to go with exactly what you have until I can get it to work, then I'll make any necessary changes.

Thanks!

Curtis

|||

Hmm, I'm also getting the same results. I think it's safe to say I didn't test this very well. When I first wrote the function, I tested it on a report with only one page and when it outputed "Page 1 of 1", I figured it was good to go. However, after playing around with a report that is 3 pages, it's clear this function is not going to work.

I'm not really sure why we are only getting the value 1 for both globals. It is clearly accessing these globals because if you change their names it will create an error saying they are not members of "Globals". Anyway since that didn't work, I really can't think of another idea on how to output page # and total pages in the body. If you come up with a solution though, I'd be interested to see it.

Thanks,
Joel

|||

I'll see if there is anything I can come up with! If anyone else has any ideas or thoughts, feel free to share! I just do not understand why SSRS should not allow us to use pagenumbering in the data. It doesn't seem to make much sense to me.

Thanks,

Curtis

|||

Okay, so I have a solution that works for me. I do not know if it will be a fix all for everyone interested, but I would like to share anyway. I was talking to our SQL developer about my issues with using page numbering in my data. In my case, I am building a table of contents. He intrigued me when he asked me if I thought about using my SELECT statements to predict my page numbers off of my row numbers. I can use this, because I found in my main report I had to define x number of rows per page to keep multiple detail lines of my table together. What I did in SQL is this:

SELECT

,...

, ROW_NUMBER() OVER (ORDER BY P.PRODLINE, P.PRODCLASS, P.PRODDESC) AS ROWNUMBER

, ((ROW_NUMBER() OVER (ORDER BY P.PRODLINE, P.PRODCLASS, P.PRODDESC)) / 50) + 4 AS PAGENUMBER

...

I determined my table of contents will always be three pages, and I know that I have fifty rows per page. I have run my 200+ page report and compared random sections in my TOC to my report, and I found it was accurate. If there are any questions, please feel free to ask. I would be more than happy to clarify if it is necessary.

|||Thanks for the post. I was thinking about trying something like that myself, good idea.