473,781 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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>
Feb 5 '07 #1
1 6758
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.dcw rote in message
news:e9******** *****@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>
Feb 12 '07 #2

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

Similar topics

0
7389
by: Pankaj Jain | last post by:
Hi All, I have a class A which is derived from ServicesComponent to participate in automatic transaction with falg Transaction.Required. Class A is exposed to client through remoting on Http channal hosting into IIS. There is a class B which is also available through remoting hosted on IIS on the same URI. B creates new of A inside a function. It succeed and able to create instance of A inside B first time. But it failes in 2nd attempt when...
3
13010
by: Imran Aziz | last post by:
Hello All, I am getting the following error on our production server, and I dont get the same error on the development box. Unable to cast object of type 'System.Byte' to type 'System.String'. here is the code that I used to create a table and then add columns to it later, later I populate the rows in the table.
15
26302
by: mr.peteryu | last post by:
Hi, Can someone explain the idea behind casting to an interface? For example: -> I have an IInterface that contains a Read() method. -> I have an object "obj" that implements IInterface. Why would someone do the following and what does it mean?
0
1631
by: hlyall1189 | last post by:
Hi, I recently started upgrading some of my old vs 2003 apps to vs 2005 and used the conversion tool but now i get the following error after building the page. I have typecasted the lines as follows: ((StyleSheetProvider)this.Page).GetStyleSheetPath(); Is there some different way of typecasting that needs to be done in vs2005? Thanks in advance.
9
6405
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 = CType(e.Item.FindControl("edit_name"), TextBox)
1
3111
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 'System.Web.UI.WebControls.SqlDataSource' to type 'System.Collections.IEnumerable'" on line: PageDataSource.DataSource = SqlDataSource2 Thanks for help
1
7113
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that someone who bothers to read all of it have some pointers. Note, I have posted the stack trace and the code exhibiting the problem further down so if you want to start by reading that, search for +++ Also note that I am unable to reproduce...
1
11388
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 perform edit . when i click update button It display a error message like this...... Unable to cast object of type 'System.Web.UI.WebControls.DataControlLinkButton' to type 'System.Web.UI.WebControls.TextBox'.
1
3955
by: miller.brettm | last post by:
Hi, I'm working with an ActiveX serial component that fires an event when data is received. I need to continue to use this component because it contains the ability to do Xmodem1k an d XmodemCRC comms The RX even fires and passes an Object (Type: Object) parameter. When looking @ the Locals window it shows the Type as: Object { byte } <Code>
2
2534
by: =?Utf-8?B?SmR1YW4=?= | last post by:
objImage.Height.Value
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10143
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9939
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7486
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.