Print Page | Close Window

Unable to see the data when exporting to PDF

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=8542
Printed Date: 03 May 2024 at 3:36am


Topic: Unable to see the data when exporting to PDF
Posted By: dee_rocks
Subject: Unable to see the data when exporting to PDF
Date Posted: 02 Dec 2009 at 1:37pm
Hi,
 
I am having a strange issue with Crystal reports and .NET
 
I have a very simple code where I select a Crystal template and after iterating thru the parms and the tables, want to export the report to a .PDF file. The .PDF file gets generated but it is empty.
 
The code is as below:
 

CrystalDecisions.Shared.DiskFileDestinationOptions diskOp = new CrystalDecisions.Shared.DiskFileDestinationOptions();

diskOp.DiskFileName = "c:\\test.pdf";

CrystalDecisions.Shared.ExportOptions exportOpts = _myRpt.ExportOptions;    ==> _myRPT is the ReportDocument object

exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;

exportOpts.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;

exportOpts.ExportDestinationOptions = diskOp;

_myRpt.Export(exportOpts);

Any idea why the data is not being populated? The file gets created but it is empty.

Thanks,
 



Replies:
Posted By: hilfy
Date Posted: 03 Dec 2009 at 11:29am
Where is the data for the report coming from?  If it's from a DataSet in your project, I don't see where you're setting the data source for the report.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: dee_rocks
Date Posted: 03 Dec 2009 at 2:10pm

Hi,

The data for the report is coming from the _myRpt object.

The way I am doing this is by:

1) loading the template
2) establishing the connection
3) passing the parameters to the template
4) doing a _myRpt.Refresh();

I checked and it looks like _myRpt object has "Rows" in it. Is there any other way to create the dataset? Sorry, I am new to the Crystal.

Thanks



Posted By: hilfy
Date Posted: 03 Dec 2009 at 2:15pm
Could you post your code that shows how you're setting the connection?  Thanks!
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: dee_rocks
Date Posted: 07 Dec 2009 at 12:49pm

Below is my code sample:

 DataSet dataSet;
     
      ConnectionInfo conn = new ConnectionInfo();
      conn.DatabaseName = "test";
      conn.ServerName = "test_server";
      conn.UserID = "test_user";
      conn.Password = "xxxx";
 

//Store the above connection info into a hash -- this is temp     
      Hashtable _conn = new Hashtable();
      _conn.Add("TEST", conn);
 
   _myRPT  = new ReportDocument();
   _tableLogins = new TableLogOnInfos();
 
//Load the Crystal template 
 _myRPT.Load(crystalReportPath + "test.rpt", CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy);
 

//Read all the tables from Crystal report
  foreach (Table tbl in _myRPT.Database.Tables)
      {
          //If the table name matches the connection hash
           if (_conn.ContainsKey(table.Name))
        {
          TableLogOnInfo _info = table.LogOnInfo;
         _info.ConnectionInfo = (ConnectionInfo)htCon[table.Name];
         table.ApplyLogOnInfo(_info);
         _tableLogins.Add(_info);
        }
      }

/* Set up the parms */

_myRpt.Refresh();
 
I think it looks like it does not bind the data to the crystal template.. I thought that _myRpt reporting object should contain all the data from the above logic.. so, I can just take the object and call the export by passing the export options.
 
What am i doing wrong?
 
Thanks
 


Posted By: hilfy
Date Posted: 08 Dec 2009 at 7:05am
I need to track down my code for doing this - I just got a new laptop and it's not on this one yet.  However, I think the issue is that you're trying to compare a table to a connection.  They're two different things.  So, I think it will work better if you just leave the connection as is - don't put it in a hash table - and then do something like this:

//Read all the tables from Crystal report
  foreach (Table tbl in _myRPT.Database.Tables)
  {
    TableLogOnInfo _info = table.LogOnInfo;
    _info.ConnectionInfo = conn;
    table.ApplyLogOnInfo(_info);
  }

-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: dee_rocks
Date Posted: 08 Dec 2009 at 12:32pm

I tried that .. but still no luck.. All the hash does is that only populates data for the table that is in the hash..

So basically, I am adding a table "TEST" in the hash and when I hit that table in the report, I go ahead and do the connection else I ignore it.
 
The comparison works fine if I do not export to the PDF file and I can see the data in the report viewer. The issue is that for some reason the data is either not binded or the data source is not set when I use the same report document object.



Print Page | Close Window