Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Crystal report disappear after click button next, last,...

Posted on 2006-04-06
22
Medium Priority
?
951 Views
Last Modified: 2012-05-05
Hi all,

I have already showed crystal report in ASP .NET C#, that SQL command was created at runtime.

But when I click some button in the crystal report (ex: move next, move last, show/hide group tree,...), the report disappeared.

How can I solve this problem? Please help me!

Thank you very much
0
Comment
Question by:xuanthinh
  • 11
  • 9
21 Comments
 
LVL 13

Expert Comment

by:EwaldL
ID: 16406509
sounds like the viewer object is not held in a session object? when interacting with the viewer (ie click on next page) the viewer object still has to exist so that the web page knows what to do.

Search on http://support.businessobjects.com/search/ for

walkthrough

and you will find some excellent pdf documentation on how to use crystal in .net
Especially this one should helpl
http://support.businessobjects.com/communityCS/FilesAndUpdates/rtm_web_forms_sample.zip.asp
0
 

Author Comment

by:xuanthinh
ID: 16451060
Thanks EwaldL, but your help did not solve my problem.

Let me show my code and describe more problem.

Here is my code:
=========================
public partial class ReportRun_DTSL05a1 : System.Web.UI.Page
{
    //CR Variable
    crDTSL05a crReportDocument;

    //ADO.NET Variables
    OleDbConnection adoOleDbConnection;
    OleDbDataAdapter adoOleDbDataAdapter;
    DataSet dataSet;

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        clsAuthentication Auth = new clsAuthentication();
        if (Auth.Check_Permission(Request.FilePath.ToString(), Session["User_ID"].ToString()))
        {
            Label1.Text = "OK";
        }
        else
        {
            Label1.Text = "NOK";
        }


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            //Build a connection string
            string connectionString = "Provider=MSDAORA;Data Source=report;Persist Security Info=True;User ID=report; Password=q";

            //Create and open a connection using the connection string
            adoOleDbConnection = new OleDbConnection(connectionString);

            //Build a SQL statement to query the datasource
            string sqlString = "";
            sqlString = "Select *  From users"; //this sql will create at runtime

            //Retrieve the data using the SQL statement and existing connection
            adoOleDbDataAdapter = new OleDbDataAdapter(sqlString, adoOleDbConnection);

            //Create a instance of a Dataset
            dataSet = new DataSet();

            //Fill the dataset with the data retrieved.  The name of the table
            //in the dataset must be the same as the table name in the report.
            adoOleDbDataAdapter.Fill(dataSet, "command");


            //Create an instance of the strongly-typed report object
            crReportDocument = new crDTSL05a();

            //Pass the populated dataset to the report
            crReportDocument.SetDataSource(dataSet);

            //Set the viewer to the report object to be previewed.
            CrystalReportViewer1.ReportSource = crReportDocument;
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
        }
    }
}
=========================

This code will report user list that sql command was create at runtime. But when I click some button in the crystal report (ex: move next, move last, show/hide group tree,...), the report disappeared.

If I remove the code in Button1_Click function to Page_Load function, this problem did not happen.

How can I resolve this problem. Please help me.

Thank you very much!
0
 
LVL 13

Expert Comment

by:EwaldL
ID: 16482424
Sorry, don't know what's wrong with your code. But try the tutorial I posted earlier. It will tell you how to get it working
http://support.businessobjects.com/communityCS/FilesAndUpdates/rtm_web_forms_sample.zip.asp
0
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 

Author Comment

by:xuanthinh
ID: 16484269
Hi EwaldL,

Thank you but your sample did not solve my problem.

You know, I would like to make report in ASP .NET C# that sql command was created at runtime. Please follow description to know what I do.
You can see this question http://www.experts-exchange.com/Databases/Crystal_Reports/Q_21789719.html.
And then browse this link http://support.businessobjects.com/communityCS/FilesAndUpdates/csharp_web_samples.exe.asp to download csharp_web_samples.exe file. Run this file to install example.
Then you see and run csharp_web_adonet example. It was well run after modify connectionString.
But then create new button1 to WebForm1 and move the code from Page_Load function (because I can modify sqlString after pageload) and run example. The report show seem ok, but when I click some button in the crystal report (ex: move next, move last, show/hide group tree,...), the report disappeared. If I click Button1 again, the report show again.
I don't know what reason. Please check this example and show me how to solve this problem.

Thank you very much!
0
 

Author Comment

by:xuanthinh
ID: 16504231
Any one can help me? It is urgent. Thanks in advance!
0
 
LVL 13

Expert Comment

by:EwaldL
ID: 16514113
What code did you move from page_load, and where did you move it to?

If this is in page_load i would expect you to have some problems
crReportDocument = new CrystalReport1();

Everytime you go to another page on the report this page_load gets executed. Hence whenever you go to another page the whole report gets wiped out and recreated from scratch. this crReportDocument = new CrystalReport1(); code should only be in page_init.

That's my understanding at least...
0
 

Author Comment

by:xuanthinh
ID: 16521854
Hi EwaldL,

I will show you the code with error and the code with out error. If you don't mind please let me know your email, I will send you the complete code with error.

Here is code with error
=========================
public partial class ReportRun_DTSL05a1 : System.Web.UI.Page
{
    //CR Variable
    crDTSL05a crReportDocument;

    //ADO.NET Variables
    OleDbConnection adoOleDbConnection;
    OleDbDataAdapter adoOleDbDataAdapter;
    DataSet dataSet;

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        clsAuthentication Auth = new clsAuthentication();
        if (Auth.Check_Permission(Request.FilePath.ToString(), Session["User_ID"].ToString()))
        {
            Label1.Text = "OK";
        }
        else
        {
            Label1.Text = "NOK";
        }


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            //Build a connection string
            string connectionString = "Provider=MSDAORA;Data Source=report;Persist Security Info=True;User ID=report; Password=q";

            //Create and open a connection using the connection string
            adoOleDbConnection = new OleDbConnection(connectionString);

            //Build a SQL statement to query the datasource
            string sqlString = "";
            sqlString = "Select *  From users"; //this sql will create at runtime

            //Retrieve the data using the SQL statement and existing connection
            adoOleDbDataAdapter = new OleDbDataAdapter(sqlString, adoOleDbConnection);

            //Create a instance of a Dataset
            dataSet = new DataSet();

            //Fill the dataset with the data retrieved.  The name of the table
            //in the dataset must be the same as the table name in the report.
            adoOleDbDataAdapter.Fill(dataSet, "command");


            //Create an instance of the strongly-typed report object
            crReportDocument = new crDTSL05a();

            //Pass the populated dataset to the report
            crReportDocument.SetDataSource(dataSet);

            //Set the viewer to the report object to be previewed.
            CrystalReportViewer1.ReportSource = crReportDocument;
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
        }
    }
}
=========================


Here is code with not error
=========================
public partial class ReportRun_DTSL05a1 : System.Web.UI.Page
{
    //CR Variable
    crDTSL05a crReportDocument;

    //ADO.NET Variables
    OleDbConnection adoOleDbConnection;
    OleDbDataAdapter adoOleDbDataAdapter;
    DataSet dataSet;

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        clsAuthentication Auth = new clsAuthentication();
        if (Auth.Check_Permission(Request.FilePath.ToString(), Session["User_ID"].ToString()))
        {
            Label1.Text = "OK";
        }
        else
        {
            Label1.Text = "NOK";
        }

        try
        {
            //Build a connection string
            string connectionString = "Provider=MSDAORA;Data Source=report;Persist Security Info=True;User ID=report; Password=q";

            //Create and open a connection using the connection string
            adoOleDbConnection = new OleDbConnection(connectionString);

            //Build a SQL statement to query the datasource
            string sqlString = "";
            sqlString = "Select *  From users"; //this sql will create at runtime

            //Retrieve the data using the SQL statement and existing connection
            adoOleDbDataAdapter = new OleDbDataAdapter(sqlString, adoOleDbConnection);

            //Create a instance of a Dataset
            dataSet = new DataSet();

            //Fill the dataset with the data retrieved.  The name of the table
            //in the dataset must be the same as the table name in the report.
            adoOleDbDataAdapter.Fill(dataSet, "command");


            //Create an instance of the strongly-typed report object
            crReportDocument = new crDTSL05a();

            //Pass the populated dataset to the report
            crReportDocument.SetDataSource(dataSet);

            //Set the viewer to the report object to be previewed.
            CrystalReportViewer1.ReportSource = crReportDocument;
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    }
}
=========================
0
 
LVL 13

Expert Comment

by:EwaldL
ID: 16529057
My guess would be that with the code that's working, every time you click on a button in the viewer, the whole dataset gets recreated. Can you try checking on that in debug mode? I haven't got a .net system easily at hand at the moment, so can't try it out myself.

If that's the case, then the viewer object does not remain it's state. So the working code only works, because everytime you click a button on the viewr, the load_page gets executed and the report is passed to the viewer again. Hence if this code is not in the load_page, clicking for the next page cannot display anything.

This might happen, if you instantiate a viewer's form through code, and this form object goes out of scope. IS that's what's happenning?
0
 

Author Comment

by:xuanthinh
ID: 16531466
Yes, you true, it happen. But I don't think there is no solution for it. I also can't debug for event when I click button in the viewer.

Any one can help me. Thank you very much!
0
 
LVL 13

Expert Comment

by:EwaldL
ID: 16541387
I am sure there is a solution for it. The problem might rather be with the code where you instantiate the viewer's page. Can you please post this here, reduced to a small number of lines that still reproduce the issue
0
 

Author Comment

by:xuanthinh
ID: 16541587
hi EwaldL,

Please let me know your email, I will send you the complete code. It is only small sample. My email is hntiger2001@yahoo.com. The small code I have already described above.

Thanks a lot!
0
 
LVL 13

Expert Comment

by:EwaldL
ID: 16546790
Sorry, i think that's against the rules here. just reduce the code to the essential bits and post it here. should only be a dozen lines or so
0
 

Author Comment

by:xuanthinh
ID: 16550514
EwaldL, the reduce of code I have just post at 04/24/2006 11:25AM JST. Please see described code above.
0
 
LVL 13

Expert Comment

by:EwaldL
ID: 16556657
we need to see the code that instantiates the class ReportRun_DTSL05a1 , i couldnt find that above
0
 

Author Comment

by:xuanthinh
ID: 16558753
Hi EwaldL,
Here below is complete class ReportRun_DTSL05a1: This code have that problem

===============================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class ReportRun_DTSL05a1 : System.Web.UI.Page
{
    //CR Variable
    crDTSL05a crReportDocument;

    //ADO.NET Variables
    OleDbConnection adoOleDbConnection;
    OleDbDataAdapter adoOleDbDataAdapter;
    DataSet dataSet;

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        clsAuthentication Auth = new clsAuthentication();
        if (Auth.Check_Permission(Request.FilePath.ToString(), Session["User_ID"].ToString()))
        {
            Label1.Text = "OK";
        }
        else
        {
            Label1.Text = "NOK";
        }


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            //Build a connection string
            string connectionString = "Provider=MSDAORA;Data Source=report;Persist Security Info=True;User ID=report; Password=q";

            //Create and open a connection using the connection string
            adoOleDbConnection = new OleDbConnection(connectionString);

            //Build a SQL statement to query the datasource
            string sqlString = "";
            sqlString = "Select *  From users";

            //Retrieve the data using the SQL statement and existing connection
            adoOleDbDataAdapter = new OleDbDataAdapter(sqlString, adoOleDbConnection);

            //Create a instance of a Dataset
            dataSet = new DataSet();

            //Fill the dataset with the data retrieved.  The name of the table
            //in the dataset must be the same as the table name in the report.
            adoOleDbDataAdapter.Fill(dataSet, "command");


            //Create an instance of the strongly-typed report object
            crReportDocument = new crDTSL05a();

            //Pass the populated dataset to the report
            crReportDocument.SetDataSource(dataSet);

            //Set the viewer to the report object to be previewed.
            CrystalReportViewer1.ReportSource = crReportDocument;
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
        }
    }
}

================================

and here below is class crDTSL05a

================================
    using System;
    using System.ComponentModel;
    using CrystalDecisions.Shared;
    using CrystalDecisions.ReportSource;
    using CrystalDecisions.CrystalReports.Engine;
   
   
    public class crDTSL05a : ReportClass {
       
        public crDTSL05a() {
        }
       
        public override String ResourceName {
            get {
                return "../ReportDesign/crDTSL05a.rpt";
            }
            set {
                // Do nothing
            }
        }
       
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Section Section1 {
            get {
                return this.ReportDefinition.Sections[0];
            }
        }
       
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Section Section2 {
            get {
                return this.ReportDefinition.Sections[1];
            }
        }
       
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Section Section3 {
            get {
                return this.ReportDefinition.Sections[2];
            }
        }
       
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Section Section4 {
            get {
                return this.ReportDefinition.Sections[3];
            }
        }
       
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Section Section5 {
            get {
                return this.ReportDefinition.Sections[4];
            }
        }
    }
   
    [System.Drawing.ToolboxBitmapAttribute(typeof(CrystalDecisions.Shared.ExportOptions), "report.bmp")]
    public class CachedcrDTSL05a : Component, ICachedReport {
       
        public CachedcrDTSL05a() {
        }
       
        public virtual Boolean IsCacheable {
            get {
                return true;
            }
            set {
                //
            }
        }
       
        public virtual Boolean ShareDBLogonInfo {
            get {
                return false;
            }
            set {
                //
            }
        }
       
        public virtual TimeSpan CacheTimeOut {
            get {
                return CachedReportConstants.DEFAULT_TIMEOUT;
            }
            set {
                //
            }
        }
       
        public virtual ReportDocument CreateReport() {
            crDTSL05a rpt = new crDTSL05a();
            rpt.Site = this.Site;
            return rpt;
        }
       
        public virtual String GetCustomizedCacheKey(RequestContext request) {
            String key = null;
            // // The following is the code used to generate the default
            // // cache key for caching report jobs in the ASP.NET Cache.
            // // Feel free to modify this code to suit your needs.
            // // Returning key == null causes the default cache key to
            // // be generated.
            //
            // key = RequestContext.BuildCompleteCacheKey(
            //     request,
            //     null,       // sReportFilename
            //     this.GetType(),
            //     this.ShareDBLogonInfo );
            return key;
        }
    }
================================
0
 
LVL 13

Expert Comment

by:EwaldL
ID: 16559672
Thanks for the code, I can see the class ReportRun_DTSL05a1 . But I cannot see the code that actually instantiates that class. This class should include soemthing like
ReportRun_DTSL05a1 viewerpage = new ReportRun_DTSL05a1();

another approach could be for you to explain how come you had to make those changes to the csharp_web_adonet sample (which was working for you).

0
 

Author Comment

by:xuanthinh
ID: 16560386
Hi EwaldL,

You can see the code in Button1_Click function, you will find line of code
crReportDocument = new crDTSL05a();

Another approach with csharp_web_adonet sample: Here below are what I had changed
1: Change connectionString to connect to my SQL
            connectionString = "Provider=SQLOLEDB;";
            connectionString += "Server=TH_NGANV;Database=pubs;";
            connectionString += "User ID=sa;Password=";
It was working fine because the code show report is in Page_Load function

2: Create a Button1 in WebForm1.aspx form and move all code in Page_Load function to Button1_Click function and run sample.
The WebForm1.aspx form with Button1 was showed, then click Button1 the report was show. It seem normal. But when I click Next button in the viewer the data disappear, I can see only Button1 in the brower. Then I click Button1 again the data show again.

Thanks a lot!


0
 
LVL 13

Expert Comment

by:EwaldL
ID: 16564914
But where do you instantiate the whole ReportRun_DTSL05a1 class? (not the  crDTSL05a object).
And why did you have to change the working code?
0
 

Author Comment

by:xuanthinh
ID: 16592339
Hi Ewaldl,

Please don't care crDTSL05a or ReportRun_DTSL05a1. You can follow my comment at 04/28/2006 06:10PM JST and 04/19/2006 12:47PM JST. It is standard sample from Crystal and I have only little change. So you should easy to find the problem.

Thanks.
0
 

Author Comment

by:xuanthinh
ID: 16603834
I had found the problem. The problem is when I click next button in the report viewer, load_page gets executed, so the report show nothing if I don't let code to show report in the page load. The solution is I will let the code show report in a function (name Show_Report). I  will call Show_Report function in the  Button1_Click function and add to Page_Load function the following code:
        if (Page.IsPostBack)
        {
            Report_Show();
        }

Any way, thanks Ewaldl for your help, and hope can get your help in the future.

So I will close this question.
0
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16628860
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question