2008-10-15 4 views
0

Crystal 보고서 뷰어에서 다음 단추를 클릭하면 데이터베이스에서 데이터를 다시 검색하는 대신 데이터 테이블에서 데이터를로드해야하므로 세션에 데이터를로드하려고합니다. 여기에 내 코드 ...세션로드 [페이지]로드 사용

ReportDocument rpt = new ReportDocument(); 
    DataTable resultSet = new DataTable(); 
    string reportpath = null; 

    protected void Page_Load(object sender, EventArgs e) 
    { 


     if (!Page.IsPostBack) 
     { 

      if (Request.QueryString.Get("id") == "5") 
      { 
       string publication = Request.QueryString.Get("pub"); 
       DateTime date = DateTime.Parse(Request.QueryString.Get("date")); 
       int pages = int.Parse(Request.QueryString.Get("pages")); 
       int sort = int.Parse(Request.QueryString.Get("sort")); 
       if (sort == 0) 
       { 
        reportpath = Server.MapPath("IssuesReport.rpt"); 
        rpt.Load(reportpath); 
        DataTable resultSet1 = RetrievalProcedures.IssuesReport(date,   publication, pages); 
       Session["Record"] = resultSet1; 
      } 

      DataTable report = (DataTable)Session["Record"]; 
      rpt.SetDataSource(report); 
      CrystalReportViewer1.ReportSource = rpt; 

이 코드를하려하지만 난 다음 버튼을 클릭 할 때 유효하지 않은 보고서 source..i 세션이 왜 그 날이 오류를주는 널 그게 전부 추측 것을 나에게 오류를 제공 간다 .

나는이 문제를 해결하는 방법을 모든 sugesstions을 ...

+0

코드에 누락 된 중괄호가 모두 속해있는 경우 도움이됩니다. if 문 각각의 범위가 무엇인지 알기는 어렵습니다. – tvanfosson

답변

1

난 당신이 여기에 대신 세션의 각 사용자에 대한 고유 키와 Cache 개체를 사용할 거라고 생각합니다.

의사 코드 :

var data = Cache["Record_999"] as DataTable; 
if (data == null) { 
    // get from db 
    // insert into cache 
} 
SetDataSource(data); 
+0

캐시가 요청간에 공유되므로 다른 사용자의 요청이 다른 매개 변수로 작성된 캐시 된 데이터 세트를 검색하게됩니다. Select() 메서드 필터링을 적용한 후 캐시에서 데이터를 검색하면 캐시를 사용할 수 있습니다. Session은 위의 코드를 기반으로 사용할 것입니다. – cfeduke

+0

죄송합니다. 캐시에 각 사용자의 고유 키가 있습니다. –

+0

John,이 컨텍스트에서 세션을 사용할 수없는 이유를 설명해 주시겠습니까? (나는 그렇지 않다는 가정하에 사용자 키 캐시로 에뮬레이트하는 이유입니다.) – kristian

0

문제는 세션을 사용하여에없는있다, 그것은 데이터를 검색하는시기를 결정하는 데 사용되는 로직있다. Cache는 요청간에 공유되므로 세션을 올바른 방법으로 사용할 수 있습니다. 즉, User B가 User 대신 Session 대신 Cache를 사용하는 코드를 실행 한 경우 User A가 방금 구성한 보고서를 볼 수 있습니다.

if (!Page.IsPostBack) 
{ 
    if (Request.QueryString.Get("id") == "5") 
    { 
     string publication = Request.QueryString.Get("pub"); 
     DateTime date = DateTime.Parse(Request.QueryString.Get("date")); 
     int pages = int.Parse(Request.QueryString.Get("pages")); 
     int sort = int.Parse(Request.QueryString.Get("sort")); 
     // fixed the statement below to key off of session 
     if (Session["Record"] == null) 
     { 
      reportpath = Server.MapPath("IssuesReport.rpt"); 
      rpt.Load(reportpath); 
      Session["Record"] = RetrievalProcedures.IssuesReport(date, publication, pages); 
     } 

     rpt.SetDataSource((DataTable)Session["Record"]); 
     CrystalReportViewer1.ReportSource = rpt; 
     // .... 
    } 
}  
0

`정렬이 0이 아니겠습니까? sort가 0이 아니고 처음으로 페이지에 액세스하는 경우 (Session [ "Record"]가 설정되지 않은 경우) 오류가 발생할 수 있습니다. 시도해 볼 수도 있습니다 :

if(sort==0 || Session["Record"] == null) 
{ 
// do your magic 
}