Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Unable to see the data when exporting to PDF Post Reply Post New Topic
Author Message
dee_rocks
Newbie
Newbie


Joined: 02 Dec 2009
Online Status: Offline
Posts: 4
Quote dee_rocks Replybullet Topic: Unable to see the data when exporting to PDF
    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,
 
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet 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
IP IP Logged
dee_rocks
Newbie
Newbie


Joined: 02 Dec 2009
Online Status: Offline
Posts: 4
Quote dee_rocks Replybullet 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

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet Posted: 03 Dec 2009 at 2:15pm
Could you post your code that shows how you're setting the connection?  Thanks!
 
-Dell
IP IP Logged
dee_rocks
Newbie
Newbie


Joined: 02 Dec 2009
Online Status: Offline
Posts: 4
Quote dee_rocks Replybullet 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
 
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet 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
IP IP Logged
dee_rocks
Newbie
Newbie


Joined: 02 Dec 2009
Online Status: Offline
Posts: 4
Quote dee_rocks Replybullet 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.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.