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

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

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.SqlDataSource' to
type 'System.Collections.IEnumerable'"
on line: PageDataSource.DataSource = SqlDataSource2

Thanks for help


code-behind:
-----------
Imports System.Data
Imports System.Data.OleDb

Partial Class Item
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim PageDSource As New PagedDataSource()
PageDSource.DataSource = SqlDataSource2
PageDSource.AllowPaging = True
PageDSource.PageSize = 6
End Sub
End Class


aspx file:
---------
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:prod %>"
SelectCommand="SELECT * FROM [Prod] WHERE ([ItemId] = @ItemId)">
<SelectParameters>
<asp:QueryStringParameter Name="CId" DefaultValue="1"
QueryStringField="ite" />
</SelectParameters>
</asp:SqlDataSource>
 
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.
 
Back
Top