Linq Stored Procedure type error

I have searched the web for a solution to ym problem but have yet to find someone the same issue...I am using SQL Stored procedures with LINQ2SQL and 3.5 framework. So far I have worked out the correct datatypes and return types for my calls but one call is really annoying me...and the error being returned is as follows -

System.InvalidCastException: Unable to cast object of type 'SingleResult`1[SelectTemplateAreasResult]' to type 'System.Web.UI.WebControls.DataList'.

Now the stored procedure I am calling can return both single and multiple results. I am thinking I need to use "List (of Templatearea)" but not sure how I use this new type and how to pipe it.

I have included the coding below, I would be grateful fi someone could shed some light on the correct method. Many Thanks, Simon
Dim sdc As New SocialiteDataContext()
Dim dlTemplateAreas As New DataList
dlTemplateAreas = sdc.SelectTemplateAreas(-1, Request.QueryString("TemplateID"))
Socialite.DBML Coding
<FunctionAttribute(Name:="dbo.SelectTemplateAreas")>  _
	Public Function SelectTemplateAreas(<Parameter(Name:="AreaID", DbType:="Int")> ByVal areaID As System.Nullable(Of Integer), <Parameter(Name:="TemplateID", DbType:="Int")> ByVal templateID As System.Nullable(Of Integer)) As ISingleResult(Of SelectTemplateAreasResult)
		Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod,MethodInfo), areaID, templateID)
		Return CType(result.ReturnValue,ISingleResult(Of SelectTemplateAreasResult))
	End Function
CREATE PROCEDURE SelectTemplateAreas
@AreaID int, @TemplateID int
SELECT * FROM TemplateAreas WHERE (@AreaID = -1 OR ID = @AreaID) AND (@TemplateID = -1 OR TemplateID = @TemplateID)

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Refael AckermannCommented:
I belive the problem your descring comes from line 6:
dlTemplateAreas = sdc.SelectTemplateAreas(-1, Request.QueryString("TemplateID")). Where you're trying to assign the data on to the WebControl, instead on to the WebControl's DataSource.

dlTemplateAreas.DataSource = sdc.SelectTemplateAreas(-1, Request.QueryString("TemplateID"))

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
clearchannelAuthor Commented:
Hahahahaha I didn't even notice my stupid mistake!!! I feel like a fool.

I was looking for all sorts of answers but missed that I hadn't added back in the datasource and databind methods after converting from dataset to datalist!

Let me confirm that is the only issue and I'll close the question!
Refael AckermannCommented:
Happy to help ;)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.