I am trying to bind my gridview to a stored procedure via Linq to SQL but keep getting 'Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.' I know I am supposed to convert the stored Proc .ToList, but this method is not available to me and throws an error (BC30456: 'toList' is not a member of 'Integer'). How do I get around this and why can I return some Stored procedures right to a gridview but not others?
Linq/.Net
Dim DC As New DistributionDataContext
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
GridView1.DataSource = (DC.usp_GetInvestorData(0, 50, "InvestorName", 0))
GridView1.DataBind()
End If
End Sub
StoredProc
alter Procedure [dbo].[usp_GetInvestorData](
@page int,
@page_len int,
@sortfield varchar(100),
@desc bit
)
as
begin
set nocount on
declare @rowcount int;
declare @innerrows int
select @rowcount=count(*) from dbo.Investors
if (@page*@page_len) > @rowcount
begin
set @page=(@rowcount/@page_len)
end
set @innerrows = @rowcount - (@page * @page_len)
declare @sortdesc varchar(100)
declare @sortasc varchar(100)
declare @a varchar(6)
declare @b varchar(6)
IF @desc=0
BEGIN
set @a = ' DESC '
set @b = ' ASC '
END
ELSE
BEGIN
set @a = ' ASC '
set @b = ' DESC '
END
DECLARE @sql nvarchar(1000)
SET @sql = 'SELECT TOP ' + STR(@page_len) + ' [InvestorName], [InvestorAttention], dbo.fnGetInvestorTotalByID(InvestorID) as InvestorTotal, InvestorID as InvestorID FROM
(
SELECT TOP ' + STR(@innerrows) + ' [InvestorName],
[InvestorAttention],
dbo.fnGetInvestorTotalByID(InvestorID) as InvestorTotal,
InvestorID as InvestorID
FROM
[dbo].[Investors]
ORDER BY [dbo].[Investors].' + @sortfield + @a + '
) Alias
ORDER BY Alias.' + @sortfield + @b
EXEC (@sql);
end