Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 13th, 2010, 11:23 AM
Authorized User
 
Join Date: Jan 2010
Location: Wales, UK
Posts: 31
Thanks: 5
Thanked 2 Times in 2 Posts
Default Problem with linq code

Hi, Im trying to return the 3 most recent articles from a newsarticle table but getting an error "Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource." I want to populate 3 DetailsView controls. The intellisense shows nothing as wrong, I have created the diagram and the ptpDataContext class. Any idea where Im going wrong?

Code:
 
  Using ptpDataContext As New ptpDataContext()

Dim latest = (From r In ptpDataContext.tblNewsArticles Order By r.ArticleID Descending Select r).First()

Dim secondLatest = (From r In ptpDataContext.tblNewsArticles Order By r.ArticleID Descending Select r).Skip(1).Take(1)

Dim thirdLatest = (From r In ptpDataContext.tblNewsArticles Order By r.ArticleID Descending Select r).Skip(2).Take(1)

DetailsView1.DataSource = latest
DetailsView1.DataBind()

DetailsView2.DataSource = secondLatest 
DetailsView2.DataBind()

DetailsView3.DataSource = thirdLatest 
DetailsView3.DataBind()

        End Using
Reply With Quote
  #2 (permalink)  
Old April 13th, 2010, 01:28 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Is this related to my book somehow? If not, you're better off posting in a more general ASP.NET fourm. That keeps this forum a bit cleaner, and gives you more views and potential answers: http://p2p.wrox.com/asp-net-3-5-436/

If it is related, can you specify page and/or chapter numbers?

That said: First() returns a single item, while the DataSource control expects a collection of items. Although the DetailsView presents one item at a time, it's designed to work with multiple items.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old April 13th, 2010, 05:24 PM
Authorized User
 
Join Date: Jan 2010
Location: Wales, UK
Posts: 31
Thanks: 5
Thanked 2 Times in 2 Posts
Default

Ok sorry, Imar. I was using writing my own code based on code from your book's linq chapter p436, but have just got what I needed by looking at the code behind of the /reviews/view-details.aspx code behind. I'll use the correct forum in future
Reply With Quote
  #4 (permalink)  
Old April 13th, 2010, 05:33 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

No problem. Glad to hear you found what you needed.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linq Problem sridharnetha C# 2005 1 December 29th, 2009 07:31 AM
LINQ vaibhavgoe LINQ 4 December 21st, 2009 03:49 PM
LINQ to SQL or not? gvdamn BOOK: Professional DotNetNuke Module Programming ISBN: 978-0-470-17116-5 2 August 20th, 2009 05:08 AM
LINQ Tutorial manish .NET Framework 3.5 1 August 13th, 2009 01:07 PM
LINQ video from Atlanta Code Camp jminatel Forum and Wrox.com Feedback 0 June 13th, 2006 08:24 AM



All times are GMT -4. The time now is 09:22 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.