This is a migrated thread and some comments may be shown as answers.

LinqDataSource and Stored Procedures

2 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mabs
Top achievements
Rank 1
mabs asked on 11 May 2010, 10:53 AM
I am trying to get a basic grid working using a linqDataSource which is populated with a stored procedure.

    <div style="width:100%;overflow:auto;"
 
        <telerik:RadGrid ID="RadGrid1" Width="3000px" AllowPaging="True" PageSize="15" runat="server" AllowSorting="true" 
            GridLines="None" DataSourceID="linq_mySP"
            <MasterTableView Width="100%" /> 
            <PagerStyle Mode="NextPrevAndNumeric" /> 
            <FilterMenu EnableTheming="True"
                <CollapseAnimation Duration="200" Type="OutQuint" /> 
            </FilterMenu> 
        </telerik:RadGrid> 
            
    </div> 
 
     <asp:LinqDataSource AutoPage="True" ID="linq_mySP" runat="server"></asp:LinqDataSource> 


Imports System.Data 
Imports Telerik.Web.UI 
 
Partial Class gridPages_telerikGrid 
    Inherits System.Web.UI.Page 
 
 
    Protected Sub linq_mySP_Selecting(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles linq_mySP.Selecting 
        Using context As New DataClassesDataContext 
 
            Dim fromdate As DateTime = DateAdd(DateInterval.Year, -5, DateTime.Now) 
            Dim todate As DateTime = DateTime.Now 
 
            e.Result = context.spTest(49, fromdate, todate) 
 
        End Using 
    End Sub 
 
 
End Class 

The problem I have is that on page load I get an 'object reference not set to an instance error', which I believe it is refering to the grid.  I can get the grid to work not using linqDataSource by binding the data to the grid on page load, but i need to get it working using a linqDataSource.

Any help would be much appreciated.

2 Answers, 1 is accepted

Sort by
0
mabs
Top achievements
Rank 1
answered on 11 May 2010, 11:59 AM
Found one bug with the code so far, I should not be Using context, when this is changed the data will load fine into a normal gridview grid.

However when trying with the radgrid I get the error,

The query results cannot be enumerated more than once.


0
mabs
Top achievements
Rank 1
answered on 11 May 2010, 12:21 PM
fixed it,

changed

e.Result = context.spTest(49, fromdate, todate)

to

e.Result = (context.spTest(49, fromdate, todate) ).ToList()



Tags
Grid
Asked by
mabs
Top achievements
Rank 1
Answers by
mabs
Top achievements
Rank 1
Share this question
or