Link to home
Start Free TrialLog in
Avatar of xuanthinh
xuanthinh

asked on

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

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
Avatar of EwaldL
EwaldL

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
Avatar of xuanthinh

ASKER

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!
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
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 https://www.experts-exchange.com/questions/21789719/Passing-parameter-to-Crytal-report-in-ASP-NET-C.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!
Any one can help me? It is urgent. Thanks in advance!
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...
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)
    {
    }
}
=========================
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?
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!
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
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!
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
EwaldL, the reduce of code I have just post at 04/24/2006 11:25AM JST. Please see described code above.
we need to see the code that instantiates the class ReportRun_DTSL05a1 , i couldnt find that above
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;
        }
    }
================================
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).

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!


But where do you instantiate the whole ReportRun_DTSL05a1 class? (not the  crDTSL05a object).
And why did you have to change the working code?
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial