I’m trying to bind a gridview to a linq to sql query that’s using a stored procedure. When I run the page, i get the following error:
Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.
var db = new TableItemDataContext(); var q = db.sp_SearchForItems('1','2','3','4'); GridView1.DataSource = q; GridView1.DataBind();
Any Ideas?
Use the ToList() extension method to convert the query to a list of items.
This will also have the effect of running the query at the time of conversion, so you may want to see if just casting to IEnumerable would work.
Edit: to clarify based on the comment trail. The issue turns out to be with the construction of the SPROC and the inability of LINQ to detect the return value. Changing the SPROC as per Stored Procedure & LINQ, Dmbl File unable to interpret the result set allowed LINQ to detect the schema after which the SPROC could be changed back.