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

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>
 
T

Teemu Keiski

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top