Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0CBOFillCollection QuestionCBOFillCollection Question
Previous
 
Next
New Post
7/15/2009 11:19 PM
 

Hi guys.

I'm building a photo gallery module for some college project. Im trying to retrieve the number of rows afected on the query for some paging purposes. Here's the Code

1. The SqlDataProvider:

public override IDataReader GetPhotosByUser(int userId, long pageIndex, int pageSize)
        {
            SqlParameter[] collection = new SqlParameter[3];
            collection[0] = new SqlParameter("@PageIndex", pageIndex);
            collection[1] = new SqlParameter("@PageSize", pageSize);
            collection[2] = new SqlParameter("@UserID", userId);

            IDataReader photoReader = SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, GETPHOTOSBYUSER
                , collection);
            return photoReader;
        }

2. The Controller:

 public List<Photo> GetPhotosByUser(int userId, long pageIndex, int pageSize, ref int totalRecords)
        {
            return CBO.FillCollection<Photo>(DataProvider.Instance().GetPhotosByUser(userId, pageIndex
                , pageSize), ref totalRecords);
        }

3. The Stored Procedure:
-- =============================================
-- Author:        Jaime A. Jaramillo
-- Create date: Jul 13th, 2009
-- Description:    Gets a Set of Photos from a given user
-- =============================================
CREATE PROCEDURE [dbo].[SN_PHOTOALBUM_USP_GET_PHOTOS_BY_USER]
    @UserID AS INT
    ,@PageIndex AS BIGINT
    ,@PageSize AS INT
   
AS
BEGIN
    --First Calculate the page bounds
    DECLARE @PageLowerBound AS BIGINT
    DECLARE @PageUpperBound AS BIGINT
    SET @PageLowerBound = @PageIndex * @PageSize
    SET @PageUpperBound = @PageSize - 1 + @PageLowerBound

    --Create a temp table for indexing
    CREATE TABLE #QueryIndex
    (
        Id int NOT NULL IDENTITY (1, 1),
        PhotoID bigint NOT NULL
    )
   
    --Then do a insert of only what you need
    INSERT INTO #QueryIndex
    (
        PhotoID
    )
    SELECT
        P.PhotoID
    FROM
        Photos AS P INNER JOIN Albums AS A
    ON
        P.AlbumID = A.AlbumID
    WHERE
        A.UserID = @UserID
    ORDER BY
        P.LastUpdate DESC
        ,P.CreationDate DESC   


    --Finally Select the page your currently querying

    SELECT
        P.PhotoID
        ,P.AlbumID
        ,P.Guid
        ,P.Width
        ,P.Height
        ,P.Url
        ,P.Title
        ,P.Comment
        ,P.CreationDate
        ,P.LastUpdate
    FROM
        Photos AS P INNER JOIN #QueryIndex AS I
    ON
        P.PhotoID = I.PhotoID
    WHERE
        I.Id >= @PageLowerBound
        AND I.Id <= @PageUpperBound
   
END

4. The Object Data Source calling the controller:

<asp:ObjectDataSource ID="odsPhoto" runat="server" OldValuesParameterformatString="original_{0}"
            SelectMethod="GetPhotosByUser" TypeName="SocialNetwork.Modules.PhotoAlbum.PhotoAlbumController">
            <SelectParameters>
                <asp:Parameter DefaultValue="1" Name="userId" Type="Int32" />
                <asp:Parameter DefaultValue="1" Name="pageIndex" Type="Int64" />
                <asp:Parameter DefaultValue="8" Name="pageSize" Type="Int32" />
                <asp:Parameter DefaultValue="0" Direction="InputOutput" Name="totalRecords" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>

The totalRecords variable is supposed to be filled with the total records affected by the query... but it returns 0 always

Anybody can tell me what is wrong with my code? Thanks


Jaime A. Jaramillo
Follow me on twitter
 
New Post
7/16/2009 11:42 AM
 

After thinking the issue with my pillow, I discovered the SP wont return the total number of rows, only the paged ones (which will be 8)

Still the totalrecords is returning 0


Jaime A. Jaramillo
Follow me on twitter
 
New Post
7/21/2009 7:45 AM
 

Hi Joker,

do you select the number of rows as a second resultset? You have to do that and give the result the alias TotalRecords after that it should be possible for you to get the ref value of the function. In the CBO class following happens:

Public

Function GetTotalRecords(ByRef dr As IDataReader) As Integer

 

 

Dim total As Integer = 0If dr.Read Then

 

Try

total = Convert.ToInt32(dr(

 

total = -1

 

"TotalRecords"))Catch ex As ExceptionEnd Try

 

End If

 

 

Return totalEnd Function

.I discovered, that using an approach with () OVERinstead of temp tables speeds the application.

ROW_NUMBER

 

greats matze

 

 
New Post
7/24/2009 10:42 AM
 

matze wrote


.I discovered, that using an approach with () OVERinstead of temp tables speeds the application.

ROW_NUMBER

 

greats matze

 

 

Thanks a lot!

As soon as I get to home I'm gonna do the fix!


Jaime A. Jaramillo
Follow me on twitter
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0CBOFillCollection QuestionCBOFillCollection Question


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out