Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 13th, 2010, 11:23 AM
Authorized User
 
Join Date: Jan 2010
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
 
Old April 13th, 2010, 01:28 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
Old April 13th, 2010, 05:24 PM
Authorized User
 
Join Date: Jan 2010
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
 
Old April 13th, 2010, 05:33 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.