2013-05-14 2 views
0

GridView을 사용하여 SQL Server에서 가져온 테이블을 표시하려고합니다. 이벤트 로그입니다. GridView 컨트롤을 ObjectDataSource 컨트롤과 함께 내 페이지에 배치했습니다. 나는 구성한 다음과 같이OutOfMemoryException GridView에 ObjectDataSource 바인딩

<%@ Page Language="VB" %> 

<!DOCTYPE html PUBLIC "-//W" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html> 
<head> 
    <title></title> 
</head> 
<body> 
    <form id="Form1" method="post" runat="server"> 
    <asp:GridView ID="gvHistory" runat="server" DataSourceID="dsHistory"> 
    </asp:GridView> 
    <asp:ObjectDataSource ID="dsHistory" runat="server" SelectMethod="GetHistoryRows" 
     TypeName="AspDotNetStorefrontAdmin.ROIImportHistory"></asp:ObjectDataSource> 
    </form> 
</body> 
</html> 

은 내가 App_Code 폴더에 클래스를 만들었습니다 그러나

Imports System.Data 

Namespace AspDotNetStorefrontAdmin 

    Public Class ROIImportHistory 

     Public Shared Function GetHistoryRows() As DataTable 

      Dim localDatatable As New DataTable 

      localDatatable.Columns.Add() 
      localDatatable.Columns.Add() 
      localDatatable.Columns.Add() 
      localDatatable.Rows.Add(New Object() {"Hi", "Hi2", "Hi3"}) 

      Return localDatatable 

     End Function 
    End Class 

End Namespace 

, 나는이 실행하려고하면 나는 다음과 같은 예외가 :

무엇이 잘못 되었나요? 나는 여기서 내가 아주 기본적인 일을하고 있다고 생각했다. 나는 많은 다른 옵션을 시도하고 GridView 또는 ObjectDataSource을 제거하면 페이지가 잘 작동한다는 것을 알 수 있습니다. 내가 DataTableGridView에 직접 바인딩하면 올바르게 작동합니다.

내 목적은 필터링과 함께 진정한 페이지 매김을 얻는 것입니다. 주어진 페이지가로드 될 때마다 DataTable을로드하려고합니다.

Server Error in '/' Application. 
Exception of type 'System.OutOfMemoryException' was thrown. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.] 
    System.Reflection.Assembly._GetType(String name, Boolean throwOnError, Boolean ignoreCase) +0 
    System.Web.UI.Util.GetTypeFromAssemblies(ICollection assemblies, String typeName, Boolean ignoreCase) +201 
    System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +302 
    System.Web.UI.WebControls.ObjectDataSourceView.GetType(String typeName) +70 
    System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1692 
    System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +27 
    System.Web.UI.WebControls.DataBoundControl.PerformSelect() +261 
    System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82 
    System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +95 
    System.Web.UI.Control.EnsureChildControls() +146 
    System.Web.UI.Control.PreRenderRecursiveInternal() +61 
    System.Web.UI.Control.PreRenderRecursiveInternal() +224 
    System.Web.UI.Control.PreRenderRecursiveInternal() +224 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394 


Version Information: Microsoft .NET Framework Version:2.0.50727.6400; ASP.NET Version:2.0.50727.6387 

나는 아무 소용 thisthis를 참조했습니다.

참고 :이 코드가 동일한 응용 프로그램 풀의 동일한 서버에있는 다른 사이트에로드되어 실행되는 것으로 나타났습니다. 따라서이 문제는 구성 문제와 관련이 있다고 생각합니다.

답변

0

여기 ObjectDataSource가 잘못 사용 된 것 같습니다.

ObjectDataSource에 대한 이해는 레코드 유형을 지정하고 레코드 데이터 유형의 콜렉션을 리턴하는 "select 메소드"를 제공합니다.

번갈아서, use Entity Framework with the ObjectDataSource.

+0

위 질문에 수정 사항을 적어 두십시오. 내가 올바르게 사용하고있는 것을 볼 수 있습니다. 또한 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.select.aspx에서 볼 수 있듯이 'DataTable'은 지원되는 데이터 소스입니다. – cjbarth

0

이것이 문제의 원인인지는 모르겠지만 ObjectDataSource 컨트롤을 사용할 때 (MVC가 나오기 전에) 나는 DataObject 특성과 데이터로 데이터 소스 클래스를 꾸밀 필요가있었습니다. DataObjectMethod 특성을 사용하여 메서드를 가져 오지 않으면 ObjectDataSource 컨트롤이 내 비즈니스 논리 메서드에 바인딩되지 않습니다. 따라서 귀하의 경우에는 다음을 의미합니다.

<DataObject> 
Public Class ROIImportHistory 

    <DataObjectMethod(DataObjectMethodType.Select, True)> 
    Public Shared Function GetHistoryRows() As DataTable 

     Dim localDatatable As New DataTable 
     localDatatable.Columns.Add() 
     localDatatable.Columns.Add() 
     localDatatable.Columns.Add() 
     localDatatable.Rows.Add(New Object() {"Hi", "Hi2", "Hi3"}) 
     Return localDatatable 

    End Function 

End Class 

속성은 ObjectDataSource 컨트롤에 클래스와 메서드를 데이터 소스로 사용할 수 있음을 알려줍니다. 다시 이것이 당신의 문제의 원인인지는 모르겠지만 시도해 볼 가치가 있습니다. 이러한 특성을 등록하려면 System.ComponentModel에 대한 참조를 추가해야합니다.

+0

그게 작동하지 않았다 :( – cjbarth