Unable to cast object of type 'System.Web.UI.WebControls.SqlDataSource' to type 'System.Collections.IEnumerable'.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    Unable to cast object of type 'System.Web.UI.WebControls.SqlDataSource' to type 'System.Collections.IEnumerable'.

    Hi,

    I want to limit the amount of data shown in a page coming from a database.
    Everything works except that I get the error:
    "Unable to cast object of type 'System.Web.UI. WebControls.Sql DataSource' to
    type 'System.Collect ions.IEnumerabl e'"
    on line: PageDataSource. DataSource = SqlDataSource2

    Thanks for help


    code-behind:
    -----------
    Imports System.Data
    Imports System.Data.Ole Db

    Partial Class Item
    Inherits System.Web.UI.P age

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles Me.Load
    Dim PageDSource As New PagedDataSource ()
    PageDSource.Dat aSource = SqlDataSource2
    PageDSource.All owPaging = True
    PageDSource.Pag eSize = 6
    End Sub
    End Class


    aspx file:
    ---------
    <asp:SqlDataSou rce ID="SqlDataSour ce2" runat="server" ConnectionStrin g="<%$
    ConnectionStrin gs:prod %>"
    SelectCommand=" SELECT * FROM [Prod] WHERE ([ItemId] = @ItemId)">
    <SelectParamete rs>
    <asp:QueryStrin gParameter Name="CId" DefaultValue="1 "
    QueryStringFiel d="ite" />
    </SelectParameter s>
    </asp:SqlDataSour ce>


  • Teemu Keiski

    #2
    Re: Unable to cast object of type 'System.Web.UI. WebControls.Sql DataSource' to type 'System.Collect ions.IEnumerabl e'.

    SqlDataSource isn't itself enumerable or a resultset, it's a "middle-man"
    control to get you the resultset.

    You would need to get the resultset out of the SqlDataSource by calling it's
    Select method (with arguments), nad passing this returned object to the
    DataSource property.

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP





    "Chris" <rrtrt@sdsd.dcw rote in message
    news:e9SCQAVSHH A.488@TK2MSFTNG P06.phx.gbl...
    Hi,
    >
    I want to limit the amount of data shown in a page coming from a database.
    Everything works except that I get the error:
    "Unable to cast object of type 'System.Web.UI. WebControls.Sql DataSource'
    to type 'System.Collect ions.IEnumerabl e'"
    on line: PageDataSource. DataSource = SqlDataSource2
    >
    Thanks for help
    >
    >
    code-behind:
    -----------
    Imports System.Data
    Imports System.Data.Ole Db
    >
    Partial Class Item
    Inherits System.Web.UI.P age
    >
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles Me.Load
    Dim PageDSource As New PagedDataSource ()
    PageDSource.Dat aSource = SqlDataSource2
    PageDSource.All owPaging = True
    PageDSource.Pag eSize = 6
    End Sub
    End Class
    >
    >
    aspx file:
    ---------
    <asp:SqlDataSou rce ID="SqlDataSour ce2" runat="server"
    ConnectionStrin g="<%$ ConnectionStrin gs:prod %>"
    SelectCommand=" SELECT * FROM [Prod] WHERE ([ItemId] = @ItemId)">
    <SelectParamete rs>
    <asp:QueryStrin gParameter Name="CId" DefaultValue="1 "
    QueryStringFiel d="ite" />
    </SelectParameter s>
    </asp:SqlDataSour ce>
    >

    Comment

    Working...