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 asp.net 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
ASP.NET Code
=============
 
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
 
 
SP
==
 
CREATE PROCEDURE SelectTemplateAreas
@AreaID int, @TemplateID int
AS
SELECT * FROM TemplateAreas WHERE (@AreaID = -1 OR ID = @AreaID) AND (@TemplateID = -1 OR TemplateID = @TemplateID)
GO

Open in new window

clearchannelAsked:
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"))
dlTemplateAreas.DataBind()

Open in new window

0

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!
0
Refael AckermannCommented:
Happy to help ;)

0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.