Click here to Skip to main content
Click here to Skip to main content

Crystal Reports helper class

By , 3 Aug 2007
 

Sample Image - CrystalHelper.jpg

Introduction

Integrating Crystal Reports in a .NET application can be a real challenge. There are a number of things you need to know to successfully run reports from inside your application. The helper class described in this article offers a number of methods that can be useful when you want to integrate Crystal Reports in your .NET application. Integrating Crystal Reports will be a lot easier and faster when you use this helper class.

The helper class contains methods that will help you to:

  • Assign database connections or DataSet objects to a report
  • Print a report from code in a WinForms application
  • Export a report from code to disk in a WinForms application
  • Export a report to an ASP.NET form.
  • Download the report to an internet client from inside an ASP.NET application.
  • Tweak the way the Crystal Reports viewer presents itself in a Windows Forms application.
  • Assign values to the parameter fields.

The demo solution, which you can download, demonstrates a lot of the features of this class. You will need SQL Server 2000 with the Pubs and NorthWind database to use it.

Background

I started building this helper class a few years back, when I had to integrate Crystal Reports in an Windows GUI application. I had to solve the following problems:

  • Assign DataSet objects to a report.
  • Assign a database connection to a report.
  • Export the report to an Adobe PDF file.
  • Integrate the Crystal Reports viewer in the application.

The helper class was originally designed for use with .NET 1.1 applications. Visual Studio 2003 came with a trimmed down version of Crystal Reports 9, which was called Crystal for .NET. At this moment, Visual Studio 2005 comes with an updated version which is based on Crystal Reports 10.

Common actions handled by the CrystalHelper class

Assign a connection to a report

One of the problems most developers face when integrating Crystal Reports is getting it to work on another system. This problem is caused by the fact that Crystal requires a valid database connection. When you develop a report, this is usually a connection to your development database. But, when you deploy a report, you will need to assign the correct database connection to each table in your report. The following code shows how this can be done:

ConnectionInfo connection = new ConnectionInfo();

connection.DatabaseName = "DatebaseName";
connection.ServerName   = "ServerName";
connection.UserID       = "UserId";
connection.Password     = "Password";

// First we assign the connection to all tables in the main report
//
foreach (CrystalDecisions.CrystalReports.Engine.Table 
         table in _reportDocument.Database.Tables)
{
    // Cache the logon info block
    TableLogOnInfo logOnInfo = table.LogOnInfo;

    // Set the connection
    logOnInfo.ConnectionInfo = connection;

    // Apply the connection to the table!
    table.ApplyLogOnInfo(logOnInfo);
}

If you have one or more subreports, then it gets even more complex. You will need to perform the above action for each of the subreports. To do this, you will need to check all sections in the report, and then assign the connection info again to all tables in each subreport. For example:

foreach (CrystalDecisions.CrystalReports.Engine.Section 
         section in _reportDocument.ReportDefinition.Sections)
{
    // In each section we need to loop through all the reporting objects
    foreach (CrystalDecisions.CrystalReports.Engine.ReportObject 
             reportObject in section.ReportObjects)
    {
        if (reportObject.Kind == ReportObjectKind.SubreportObject)
        {
            SubreportObject subReport = (SubreportObject)reportObject;
            ReportDocument  subDocument = 
                            subReport.OpenSubreport(subReport.SubreportName);

            foreach (CrystalDecisions.CrystalReports.Engine.Table 
                     table in subDocument.Database.Tables)
            {
                // Cache the logon info block
                TableLogOnInfo logOnInfo = table.LogOnInfo;

                // Set the connection
                logOnInfo.ConnectionInfo = connection;

                // Apply the connection to the table!
                table.ApplyLogOnInfo(logOnInfo);
            }
        }
    }
}

The two code sections above are handled by the Open() method in the CrystalHelper class.

Assign a DataSet to a report

A similar problem occurs when you want to assign a DataSet to a report. The DataSet must be assigned not just to the report, but also to all subreports. The code to do this will look like this:

// Now assign the dataset to all tables in the main report
//
_reportDocument.SetDataSource(dsReportData);

// Now loop through all the sections
// and its objects to do the same for the subreports
//
foreach (CrystalDecisions.CrystalReports.Engine.Section section 
         in _reportDocument.ReportDefinition.Sections)
{
    // In each section we need to loop through all the reporting objects
    foreach (CrystalDecisions.CrystalReports.Engine.ReportObject 
             reportObject in section.ReportObjects)
    {
        if (reportObject.Kind == ReportObjectKind.SubreportObject)
        {
            SubreportObject subReport = (SubreportObject)reportObject;
            ReportDocument  subDocument = 
               subReport.OpenSubreport(subReport.SubreportName);

            subDocument.SetDataSource(dsReportData);
        }
    }
}

This code is also part of the Open() method in this CrystalHelper class.

Using the code to integrate a report

Print report

The first code sample shows how you can print a report when the report is an embedded resource and the data is stored in a DataSet:

private void PrintReport(SqlConnection connection)
{
    using (DataSet ds = new TestData())
    {
        SqlHelper.FillDataset(connection,
            CommandType.Text, "SELECT * FROM Customers", ds, new string [] {"Customers"});
    
        using (CrystalHelper helper = new CrystalHelper(new TestReport()))
        {
            helper.DataSource = ds;
            helper.Open();
            helper.Print();
            helper.Close();
        }
    }                                      
}

As you can see, in this example, the code to handle the report is very simple and straightforward. The Open() method will ensure the DataSet is assigned to all sections.

When you use embedded queries in your report, then you will need to assign the database connection instead of assigning a DataSet as in the example above. The code would then look like this:

private void PrintReport()
{ 
    using (LCrystalHelper helper = new LCrystalHelper(new TestReport()))
    {
        helper.DatabaseName = "DatabaseName";
        helper.ServerName   = "ServerName";
        helper.UserId       = "User";
        helper.Password     = "Password";
                    
        helper.Open();
        helper.Print();
        helper.Close();
    }                                      
}

Again, you see that using Crystal Reports with this helper class makes integrating reports very simple. In the example above, I used a fully qualified connection with a valid user ID and password. The version of Crystal Reports that is included with Visual Studio 2005 also supports integrated security. For that purpose, the CrystalHelper class also features a property IntegratedSecurity. This property defaults to false, but setting it to true will allow you to use integrated security, as show in this example:

private void PrintReport()
{ 
    using (LCrystalHelper helper = new LCrystalHelper(new TestReport()))
    {
        helper.DatabaseName = "DatabaseName";
        helper.ServerName   = "ServerName";
        helper.IntegratedSecurity = true;
                    
        helper.Open();
        helper.Print();
        helper.Close();
    }                                      
}

If the report is included in your solution as a content file, rather than an embedded resource, then you can replace this line:

using (CrystalHelper helper = new CrystalHelper(new TestReport()))

with this line:

using (CrystalHelper helper = new CrystalHelper(@"C:\ReportLocation\ReportFile.rpt"))

Export a report

Exporting a report can be done to the following Export formats:

  • Word (*.doc)
  • Excel (*.xls)
  • Rich text (*.rtf)
  • Portable Doc Format (*.pdf)

The helper class features four methods to perform an export. The first two simply export the file to a specified location. These two methods are useful for WinForms applications, or when you need to export files to a server in an ASP.NET environment. The first of these has a file name as an argument. The type of export is determined by checking the extension given to the file:

helper.Export(@"C:\ExportLocation\MyFile.pdf");

The second method also allows you to specify the Export format as an argument:

helper.Export(@"C:\ExportLocation\MyFile.pdf", CrystalExportFormat.PortableDocFormat);

When you use these methods in an ASP.NET application, you will probably want the files to be exported to the client. For this purpose, the helper class implements two methods which require you to pass the HttpResponse object. The first of these methods will simply write the exported file to the response:

helper.Export(Response, CrystalExportFormat.PortableDocFormat);

This will result in the report being shown inside the client internet browser, provided the application that supports the export format is installed. The second method allows you to specify if the export has to be sent as an attachment, in which case you can specify the file name for the export. The user will be shown a dialog in which he/she can specify a download location.

helper.Export(Response, CrystalExportFormat.PortableDocFormat, 
              true, "AnExportedDocument.pdf");

Showing the report in the Crystal Reports viewer control

The last option to show a report is using the Crystal Reports viewer control. Assuming you have the control on your form (Windows or ASP.NET), you can do the following:

private void PrintReport(SqlConnection connection)
{
    using (DataSet ds = new TestData())
    {
        SqlHelper.FillDataset(connection, 
            CommandType.Text, "SELECT * FROM Customers", 
                              ds, new string [] {"Customers"});
    
        CrystalHelper helper = new CrystalHelper(@"C:\ReportLocation\ReportFile.rpt");
        helper.DataSource = ds;
        helper.Open();
        crystalReportViewer1.ReportSource = _crystalHelper.ReportSource;
    }                                      
}

Setting the values for report parameters

To set a value for a parameter, you would normally need to write about 6 lines of code. And, you will need to know when to do this. Normally, just before assigning the database connection. The helper class also assists you in setting values for the report parameter fields by providing the SetParameter method. The class will keep an internal list of all the parameters you wish to set, and will apply the values at the right time. The following example shows you how you can use this method:

using (CrystalHelper hlp = new CrystalHelper())
{
    _crystalHelper.SetParameter("CategoryId", "Beverages");

    _crystalHelper.ServerName   = "localhost";
    _crystalHelper.DatabaseName = "Pubs";
    _crystalHelper.UserId       = "UserId";
    _crystalHelper.Password     = "Password";

    _crystalHelper.ReportSource = new TestReport();

    _crystalHelper.Open();
    _crystalHelper.Export("C:\\Test.pdf", 
                          CrystalExportFormat.PortableDocFormat);
    _crystalHelper.Close();
}

The demo solution which you can download here also demonstrates this feature.

Tweaking the Crystal Reports viewer control

Change the name of a tab

When the report is shown, the viewer will always show a tab. This is a very useful feature when you have subreports or drill-down features in your report. The only thing is that the name of the tab is always "Main Report" or the name of your subreport. Changing the name of a tab is easily done by making the following call:

CrystalHelper.ReplaceReportName(crystalReportViewer1, 
             "MainReport", "My name for the report");

The first argument is the viewer control. The second is always the current name of the tab. The last argument is the new name for the tab. You need to be aware though, that changing the names of the tabs is a bit tricky. First of all, you are only sure that the first tab (MainReport) is always there. The other tabs are only shown when a user clicks to enter a subreport or drill-down section. You will need to respond to the events thrown by the viewer to make sure the names of the tabs are adjusted when a new tab is made visible.

Hide the tabs

If you want to hide the tabs, then you can simply use this call:

CrystalHelper.ViewerTabs(crystalReportViewer1, false);

This is of course reversible by calling the same method with true as the second argument.

Hide the statusbar

The report viewer also shows a status bar. This can be hidden by using the following call:

CrystalHelper.ViewerStatusBar(crystalReportViewer1, false);

This is of course reversible by calling the same method with true as the second argument.

Valuable resources

A lot of the information I needed to build this helper class was found on the Internet. I found the following resources to be very useful when you need to do something with Crystal Reports:

I strongly recommend anyone who wants to learn more about Crystal Reports to visit these links. I find most of the answers to questions related to Crystal Reports on one of the above locations.

History

August 3, 2007
  • Improved the SetParameter method.
  • Added example code to the demo solution for the SetParameter feature.
  • Restored links to .NET 1.1 versions of the code.
June 12, 2007
March 8, 2007

Fixed bug reported by Matthew Noonan.

December 6, 2006 Added .NET 1.1 version of the class and the demo application.
August 8, 2006 Included more samples and background.
August 3, 2006 Included hyperlinks to resources used to build this class.
August 2, 2006 First version published on CodeProject.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jan Schreuder
Software Developer (Senior)
Netherlands Netherlands
Member
I'm a professional software developer for a large company in the Netherlands. I have been developing software since 1988 in C, Visual Basic and C#.
 
I also blog about my work and .Net related issues on my weblog: http://bloggingabout.net/blogs/jschreuder/

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5membermanoj kumar choubey4 Apr '12 - 22:07 
Nice
QuestionPerfect ;)memberA7mad_29 Feb '12 - 5:05 
Thnx
GeneralMy vote of 5memberNitesh_r20 Jul '11 - 3:09 
I searched for hours for something like this and I'm very happy I found this. It's exactly what I needed and it is awesome. Well done
GeneralMy vote of 5memberthatraja5 Oct '10 - 22:59 
Good library
GeneralGreat Library, found issue with Crystal Report's ApplyLogOnInfo method for SubReportsmemberMattsterP3 Aug '10 - 9:09 
Thanks so much for this fantastic library, I have been using it for quite some time to make life with Crystal Reports easier. I did just recently run into an issue which I have been able to resolve related to setting credentials of Sub-reports. I tracked the issue down to the call to ApplyLogOnInfo within your AssignTableConnection function, it appears that Crystal for some reason decides to apply the main report's command to the sub-report, if I comment out that line and set up the credentials manually it seems to work fine as so:
 
//table.ApplyLogOnInfo(logOnInfo);//commented out Aug 2nd 2010 MPP for subreports 

table.LogOnInfo.ConnectionInfo.DatabaseName = connection.DatabaseName;
table.LogOnInfo.ConnectionInfo.ServerName = connection.ServerName;
table.LogOnInfo.ConnectionInfo.UserID = connection.UserID;
table.LogOnInfo.ConnectionInfo.Password = connection.Password;
table.LogOnInfo.ConnectionInfo.Type = connection.Type;
 
I have detailed this in my blog post here:
http://computercabal.blogspot.com/2010/08/deployment-of-crystal-reports-with-sub.html[^]
 
Thanks again for your library, it has really come in handy...
GeneralClose and Dispose CrystalHelper Report connectionmemberzdlewis16 Dec '09 - 11:13 
We are having issues with reports not disposing after being run. Here is the code I am using to call the CrystalHelper class:
 
string reportPath = Path.Combine(ConfigurationManager.AppSettings["ReportPath"], REPORT_NAME);
 
CrystalHelper crystalHelper = new CrystalHelper(reportPath,
	string.Empty,
	string.Empty,
	ConfigurationManager.AppSettings["UserID"],
	ConfigurationManager.AppSettings["Password"]);
 
crystalHelper.SetParameter(PARAM_QUERY, query);
crystalHelper.SetParameter(PARAM_EMPLOYEE_NO, txtEmpNoEntry.Text);
crystalHelper.SetParameter(PARAM_EMPLOYEE_NAME, lblEmployeeName.Text);
crystalHelper.SetParameter(PARAM_DIRECT_REPORTS, chkDirectReports.Checked);
crystalHelper.SetParameter(PARAM_PROGRAM_GROUPS, chkPgmGroupToggle.Checked);
crystalHelper.SetParameter(PARAM_PROGRAM, ddlProgramSelect.SelectedItem.Text.ToString());
crystalHelper.SetParameter(PARAM_PHASE, ddlPhaseSelect.SelectedItem.Text.ToString());
crystalHelper.SetParameter(PARAM_LOCATION, ddlPlantSelect.SelectedItem.Text.ToString());
crystalHelper.SetParameter(PARAM_WORKCENTER, wcCode);
crystalHelper.SetParameter(PARAM_IPT, ipt);
 
crystalHelper.Open();
crystalHelper.Export(Response, CrystalExportFormat.PortableDocFormat);
crystalHelper.Close();
crystalHelper.Dispose();
 
Any ideas why the Close() and Dispose() methods don't seem to be working correctly? Is there a better way to dispose of the report after it is presented?
GeneralRe: Close and Dispose CrystalHelper Report connectionmemberJan Schreuder22 Dec '09 - 2:13 
One way to improvee on the disposing of your reports is to encapsulate the CrystalHelper in a using block. For example:
using (CrystalHelper helper = new CrystalHelper())
{
   // Set parameters
   // Open report
   // Export report  
}
 
But that will only make CrystalHelper dispose of all the Crystal objects that it owns. I'm sure that part works fine. However, if you look at the Dispose implementation of CrystalHelper, you will see that it calls Dispose methods on CrystalReports objects. So it could also be that Crystal itself is not disposing of it's memory properly.
GeneralRe: Close and Dispose CrystalHelper Report connectionmemberzdlewis8 Jan '10 - 9:04 
Thanks so much for your help!
 
The Temp folder on our server was accumulating megabytes by the hour, which seemed to override the Crystal Report processing queue registry value (which we have set to -1).
 
I implemented your code above, and the Temp folder stays clean. Big Grin | :-D Here is a snippet of how we are implementing the CyrstalHelper class encapsulated in a using block:
 
private void RunReport()
{
	string reportPath = Path.Combine(ConfigurationManager.AppSettings["ReportPath"], REPORT_NAME);
 
	using (CrystalHelper crystalHelper = new CrystalHelper(reportPath, string.Empty, string.Empty, ConfigurationManager.AppSettings["UserID"], ConfigurationManager.AppSettings["Password"]))
	{
		crystalHelper.SetParameter(PARAM_QUERY, query);
		crystalHelper.SetParameter(PARAM_EMPLOYEE_NO, txtEmpNoEntry.Text);
		crystalHelper.SetParameter(PARAM_EMPLOYEE_NAME, lblEmployeeName.Text);
		crystalHelper.SetParameter(PARAM_DIRECT_REPORTS, chkDirectReports.Checked);
		crystalHelper.SetParameter(PARAM_PROGRAM_GROUPS, chkPgmGroupToggle.Checked);
		crystalHelper.SetParameter(PARAM_PROGRAM, ddlProgramSelect.SelectedItem.Text.ToString());
		crystalHelper.SetParameter(PARAM_PHASE, ddlPhaseSelect.SelectedItem.Text.ToString());
		crystalHelper.SetParameter(PARAM_LOCATION, ddlPlantSelect.SelectedItem.Text.ToString());
		crystalHelper.SetParameter(PARAM_WORKCENTER, wcCode);
		crystalHelper.SetParameter(PARAM_IPT, ipt);
 
		crystalHelper.Open();
		crystalHelper.Export(Response, CrystalExportFormat.PortableDocFormat);
		crystalHelper.Close();
		crystalHelper.Dispose();
	}
}
 
This seems to be the answer to our programming prayers, so we say thanks again! Thumbs Up | :thumbsup:
GeneralRe: Close and Dispose CrystalHelper Report connectionmemberJan Schreuder9 Jan '10 - 23:49 
You can remove the crystalHelper.Close() and crystalHelper.Dispose(). The using will make sure that the crystalHelper.Dispose is always called. And the Dispose method on CrystalHelper will do the close for you, if you don't. Glad it solved your problem Smile | :)
GeneralError...memberThe_Collector10 Sep '09 - 21:11 
foreach (CrystalDecisions.CrystalReports.Engine.Section
            section in rpt.ReportDefinition.Sections)
            {
                  // In each section we need to loop through all the reporting objects
                  foreach (CrystalDecisions.CrystalReports.Engine.ReportObject
                              reportObject in section.ReportObjects)
                  {
                        if (reportObject.Kind == ReportObjectKind.SubreportObject)
                        {
                              SubreportObject subReport = (SubreportObject)reportObject;
                              ReportDocument subDocument =
                                                      subReport.OpenSubreport(subReport.SubreportName);
 
                              foreach (CrystalDecisions.CrystalReports.Engine.Table
                                          table in subDocument.Database.Tables)
                              {
                                    // Cache the logon info block
                                    TableLogOnInfo logOnInfo = table.LogOnInfo;
 
                                    // Set the connection
                                    logOnInfo.ConnectionInfo = crConnectionInfo;
 
                                    // Apply the connection to the table!
                                    table.ApplyLogOnInfo(logOnInfo);
                              }
                        }
                  }
            }
 
The above code works on my Test Server but not in Production.it still ask LogOnInfo from my Test Server. what's the problem?
 
xxx

GeneralRe: Error...memberJan Schreuder14 Sep '09 - 0:42 
Most likely reason is that the connection info is not correct on the production server. Add log information to the code and check the logs after the error occurs
GeneralRe: Error...memberThe_Collector15 Sep '09 - 23:51 
Thanks for the reply...
 
I'm sure i made the correct connection since my records that im expecting are all displayed. however, part of my report is to display the parameters value passed from my page to cystal report which doesn't display the value.
below is the complete codes:
 
private void LoadReport()
      {
 
            string reportName = Session["ReportName"].ToString();
            string reportDate = Session["ReportDate"].ToString();
            string reportType = Session["ReportType"].ToString();
 
            rpt.Load(Server.MapPath("~/Reports/" + reportName.ToString()));
 
            CrystalReportViewer1.ReportSource = rpt;
 
            crConnectionInfo.ServerName = "myServer";
            crConnectionInfo.DatabaseName = "MyDatebase";
            crConnectionInfo.UserID = "myUser";
            crConnectionInfo.Password = "myUser";
 
            crDatabase = rpt.Database;
            crTables = crDatabase.Tables;
 
            //Loop through all tables in the report and apply the connection information for each table.
            for (int i = 0; i < crTables.Count; i++)
            {
                  crTable = crTables[i];
                  crTableLogOnInfo = crTable.LogOnInfo;
                  crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
                  crTable.ApplyLogOnInfo(crTableLogOnInfo);
                  crTable.Location = "MyDatabase.dbo." + crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1);
            }
 
            foreach (CrystalDecisions.CrystalReports.Engine.Section
            section in rpt.ReportDefinition.Sections)
            {
                  // In each section we need to loop through all the reporting objects
                  foreach (CrystalDecisions.CrystalReports.Engine.ReportObject
                              reportObject in section.ReportObjects)
                  {
                        if (reportObject.Kind == ReportObjectKind.SubreportObject)
                        {
                              SubreportObject subReport = (SubreportObject)reportObject;
                              ReportDocument subDocument =
                                                      subReport.OpenSubreport(subReport.SubreportName);
 
                              foreach (CrystalDecisions.CrystalReports.Engine.Table
                                          table in subDocument.Database.Tables)
                              {
                                    // Cache the logon info block
                                    TableLogOnInfo logOnInfo = table.LogOnInfo;
 
                                    // Set the connection
                                    logOnInfo.ConnectionInfo = crConnectionInfo;
 
                                    // Apply the connection to the table!
                                    table.ApplyLogOnInfo(logOnInfo);
                                    table.Location = "MyDatabase.dbo." + table.Location.Substring(table.Location.LastIndexOf(".") + 1);
                              }
                        }
                  }
            }
           
            //Set the viewer to the report object to be previewed.
            CrystalReportViewer1.ReportSource = rpt;
           
            ParameterDiscreteValue discreteBranch = new ParameterDiscreteValue();
            ParameterFields paramFields = new ParameterFields();
           
            ParameterDiscreteValue paramDiscreteBranch = new ParameterDiscreteValue();
            ParameterField paramFieldBranch = new ParameterField();
            paramFieldBranch.Name = "@pBranchCode";
            paramDiscreteBranch.Value = Session["branchCode"].ToString();
            paramFieldBranch.CurrentValues.Add(paramDiscreteBranch);
            paramFields.Add(paramFieldBranch);
 
            ParameterDiscreteValue paramDiscreteTranDate = new ParameterDiscreteValue();
            ParameterField paramFieldTranDate = new ParameterField();
            paramFieldTranDate.Name = "@pTransactionDate";
            paramDiscreteTranDate.Value = reportDate;
            paramFieldTranDate.CurrentValues.Add(paramDiscreteTranDate);
            paramFields.Add(paramFieldTranDate);
        
            CrystalReportViewer1.ParameterFieldInfo = paramFields;
 
            discreteBranch.Value = Session["branchName"].ToString();
            rpt.SetParameterValue("BranchName", discreteBranch);
            discreteBranch.Value = Session["branchaddress"].ToString();
            rpt.SetParameterValue("BranchAddress", discreteBranch);
           
      }
 
"@pBranchCode" and "@pTransactionDate" can not be displayed in the actual report however Stored procedure received the right value.
 
SUBREPORTS   will also fail because it will receive a null value from both "@pBranchCode" and "@pTransactionDate".

hoping for your solution... thank you
 
xxx

Generalto divide report in halfs sheet using crystal reportmemberkatmeena7 Jul '09 - 5:41 
i want to print two different employee detail in half sheet in a4 size paper using crystal report...
can somebody know how to do this in half half sheet within one paper..pls if anyone knows pls post answer as soon as possible..
Thanks
QuestionCan this be used for an ODBC connection?memberEd Cohen26 May '09 - 14:24 
Jan,
Great work. I just found your code and downloaded it. Question, is there anyway for your class to be used with an ODBC connection? Yes, I know it is an old technology, but I have some software that uses it. I will be upgrading this to OLEDB in the future. By the way, in the demo code I noticed an SQL helper class. This will be very interesting for me. Thanks a bunch!
 
Ed Cohen
AnswerRe: Can this be used for an ODBC connection?memberJan Schreuder26 May '09 - 21:04 
Never tested it myself, but I think it could work.
GeneralSubreportsmemberIgorAcidRain12 Mar '09 - 0:12 
Good article. Thanks a lot.
But I have some troubles.
It works well when I change Name of Main Report, but when I try to do the same thitg to subreport it doesn't work. I react DrillDownSubreport Event of CrystalReportsViewer and then use function ReplaceReportName. I'm sure that all of the parameters of this function are right. But nothing happens.
Maybe I do something wrong. Please help me.
GeneralCrystal report editing at run time.......memberMuhammad Umar Siddique21 Feb '09 - 1:55 
I want to give options to end users of my desktop application to change the layout of reports as per requirements. Like change the order of columns or change report header text etc. Can anyone help me regarding this ?
 
Thanks Sniff | :^)
 
Muhammad Umar Siddique..

Questionfrom table i need 1 customer details onlymembershantuju17 Feb '09 - 1:47 
in my table i have a lot of patients, but i only need 1 patient information, what should i do ?
GeneralVisual Studio 2008 Problem.......memberMuhammad Umar Siddique16 Feb '09 - 6:23 
Hi Jan Schreuder!
 
Thanks for sharing your efforts with us. I tried to used the library in my C# window's application using VS 2008. Am getting following error while loading the report in viewer.
 
ERROR: "Load report failed..."
 
Below is the code.
 

try
{
SqlConnection con = new SqlConnection("connection info.");
SqlHelper.FillDataset(con, CommandType.Text, "SELECT * FROM Customers", ds, new string[] { "Customers" });
using (CrystalHelper helper = new CrystalHelper(@"C:\rptTest.rpt"))
{
helper.DataSource = ds;
helper.Open();
crystalReportViewer1.ReportSource = helper.ReportSource;
helper.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
 
}
 

Please help me to find out some solution....
 

Any kind of help or assistance will be appreciated.
 
Thanks Cool | :cool:
 
Muhammad Umar Siddique..

GeneralConvert windows.forms into web.formsmemberBabu.R.K6 Feb '09 - 23:53 
I want to use your code in my web project.
 
how to change this two functions
 
1 ViewerTabs
2 ReplaceReportName
 
into web forms in the file CrystalHelper.cs
 

TabPage tab = (TabControl)((PageView)control).Controls[0];
 
if (!visible)
{
tab.ItemSize = new Size(0, 1);
tab.SizeMode = TabSizeMode.Fixed;
tab.Appearance = TabAppearance.Buttons;
}
else
{
tab.ItemSize = new Size(67, 18);
tab.SizeMode = TabSizeMode.Normal;
tab.Appearance = TabAppearance.Normal;
}
 
Thanks
Babu Kumarasamy
GeneralUnable to connect: incorrect log on parametersmemberfast freddie19 Dec '08 - 6:45 
Hi Jan -
 
First off - GREAT WORK! The Helper has been great for our reports that do not contain a sub report. However - I've tried and tried to get sub reports to work but have not been successful. For awhile we were receiving the "Operation Illegal on Linked Parameter" error.
 
I read in another posting to put the variable being passed from the main report into a forumla. I've done this and have the report working while within VS 2005. However, when I run the report - I'm now getting "Unable to connect: incorrect log on parameters" error.
 
The main report has two tables. If I remove the subreport, the main report runs correctly - exporting to PDF. (Note: We are NOT using the report viewer).
 
Do you have any suggestions?
 
Thank You!
 
fast freddie
 
"The larger the island of knowledge, the longer the shoreline of wonder" - Ralph W. Sockman

GeneralRe: Unable to connect: incorrect log on parametersmemberfast freddie19 Dec '08 - 10:47 
OK.. I now have it back to "Operation illegal on Linked Parameter" error. Could you explain 'how' to link a value from the main report to a subreport? I've tried everything I've been able to find - but continue to get this error. Any assistance would be greatly appreciated!
 
Thanks!
 
fast freddie
 
"The larger the island of knowledge, the longer the shoreline of wonder" - Ralph W. Sockman

GeneralRe: Unable to connect: incorrect log on parametersmemberfast freddie5 Jan '09 - 10:23 
Ron Chapman (see below) had the fix all along.
 
I'm not sure what I missed on my first attempt at following his instructions - but, in this case, the second time was the charm. We made the change (two lines) to the CrystalHelper class, re-built, and rebuilt the reference to the new dll.
 
Works like a charm now! Smile | :)
 
fast freddie
 
"The larger the island of knowledge, the longer the shoreline of wonder" - Ralph W. Sockman

QuestionSystem.AccessViolationExceptionmemberhsalim15 Sep '08 - 8:42 
I am using the AssignConnection method in my code and am getting this exception when i close the project.
 

System.AccessViolationException was unhandled
Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
 
Stack Trace:
at _cexit()\r\n
at <CrtImplementationDetails>.LanguageSupport._UninitializeDefaultDomain(Void* cookie)\r\n
at <CrtImplementationDetails>.LanguageSupport.UninitializeDefaultDomain()\r\n
at <CrtImplementationDetails>.LanguageSupport.DomainUnload(Object source, EventArgs arguments)\r\n
at <CrtImplementationDetails>.ModuleUninitializer.SingletonDomainUnload(Object source, EventArgs arguments)"
 

Any idea what this means?
AnswerRe: System.AccessViolationExceptionmemberMember 540677911 Mar '10 - 5:52 
The AccessViolationException was raised after first load of the page; I don't know why but the file isn't released the right way; any access after the first one causes an AccessViolationException
 
I fixed the problem putting all the code for Logon and SetConnectionInfos under an if(!IsPostBack) clause, and the application started working.
 
emanuele.greco

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 3 Aug 2007
Article Copyright 2006 by Jan Schreuder
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid