473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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.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>
Feb 5 '07 #1
1 3061
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
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"Chris" <rr***@sdsd.dcwrote in message
news:e9*************@TK2MSFTNGP06.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.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>
Feb 12 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2...
9
by: Jim in Arizona | last post by:
I get this error: Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlInputText' to type 'System.Web.UI.WebControls.TextBox'. Using this code: Dim test3 As TextBox test3 =...
1
by: Chris | last post by:
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...
0
by: Pieter | last post by:
Hi, I'm using NHibernate 1.2 (CR1), and I'm using a custom list (inherited from BindingList(Of T) ) for all my lists. The NHibernate documentation told me that I had to implement...
0
by: David C | last post by:
I am getting this error in the Databound event of a GridView and I am having a difficult time debugging. I do not get the error on every record that I edit in the GridView. The error is occurring...
1
by: sana krishna | last post by:
Hai, Pls anyone help me........................... I am using ASP.NET(C#). I want to display the data in a gridview and make the gridview to become editable and insert and delete. But i can't...
4
by: Tony | last post by:
Hello! Below I have a complete working program.with some simple classes one of these is a generic class. The question is about this method GetCows() {...} which is a member in the generic...
20
by: raylopez99 | last post by:
Inspired by Chapter 8 of Albahari's excellent C#3.0 in a Nutshell (this book is amazing, you must get it if you have to buy but one C# book) as well as Appendix A of Jon Skeet's book, I am going...
11
by: KMinFL | last post by:
This is a C# VS 2008 question... Our system has 2 base classes, SingleEntity and NewPluralEntity. SingleEntity provides access to properties and methods related to manipulating data in a database...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.