Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 7th, 2007, 09:44 AM
Friend of Wrox
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default PagedDataSource: what's wrong in this code?


I posted this topic yesterday but i correct a lot myself, still with the same error(s). So i post it again. Thanks.

I try to implement paging with PagedDataSource but i get two different errors:

with the line: "PageDataSource.DataSource = ds" i get the error:
"Unable to cast object of type 'System.Data.DataSet' to type 'System.Collections.IEnumerable"

with the line: "PageDataSource.DataSource = p" i get the error:
"Cannot compute Count for a data source that does not implement ICollection"

I thougt Dataset implements class IEnumerable ...

Can anybody tell me what to change in this code?


 Dim PageDataSource As New PagedDataSource()
        Dim ds As DataSet
        Dim d As SqlDataAdapter
        Dim sql As String
        Dim sConnectionString As String
        Dim x As Integer
        Dim p As String

        sConnectionString = System.Configuration.ConfigurationManager.Connecti onStrings("prod").ToString()
        sql = "SELECT * FROM [Product]"
        d = New SqlDataAdapter(sql, sConnectionString)
        ds = New DataSet()
        x = d.Fill(ds)

        p = ds.Tables(0).ToString
        PageDataSource.DataSource = ds
    'PageDataSource.DataSource = p
        PageDataSource.AllowPaging = True
        PageDataSource.PageSize = 4

        DataList1.DataSource = PageDataSource

aspx file:

  <asp:DataList ID="DataList1" runat="server">

Old February 7th, 2007, 10:41 AM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

AFAIK, you can't set the DataSet directly. Instead, assign one of the tables:

    PageDataSource.DataSource = ds.Tables(0).DefaultView


Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Old February 7th, 2007, 02:39 PM
Friend of Wrox
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks, it works now.

Similar Threads
Thread Thread Starter Forum Replies Last Post
what's wrong with my code? DyerOppenheimer BOOK: Beginning Ajax with ASP.NET 0 January 7th, 2008 08:46 AM
problem with pageddatasource hertendreef ASP.NET 2.0 Professional 0 February 6th, 2007 06:09 PM
What's wrong with this code? appleseed C++ Programming 2 November 25th, 2006 08:17 AM
Can anyone tell me what's wrong with this code? hobgoblin BOOK: Beginning ASP 3.0 0 March 3rd, 2005 01:47 PM
What Wrong Of My Code ck C++ Programming 0 January 27th, 2005 08:35 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.