SIGN UP MEMBER LOGIN:    
ARTICLE

BackgroundWorker and CrystalReports

Posted by hamzi khalla Articles | Crystal Reports C# September 18, 2009
The code snippet in this article shows how to get reports data from a database and generate reports using Crystal Reports in a background worker thread.
Reader Level:
Download Files:
 

I have a DBClass that is responsible for executing database queries and SPs.

Here is the code snippet that shows how to use a background thread to get data and generate reports. This is useful when main thread of your applications is doing something else, data data entry and you want reports to be generated in the background.

using System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
System.Threading;
namespace
myCryst
{
public partial class Form1 : Form
{
DataSet ds;
frmCryst f = new frmCryst();
public Form1()
{
InitializeComponent();
}
private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
{
bgWorker.ReportProgress(10);
Thread.Sleep(164);
bgWorker.ReportProgress(20);
Thread.Sleep(164);
bgWorker.ReportProgress(30);
Thread.Sleep(164);
ds =
DBClass.ExecQuery("select * from students");
bgWorker.ReportProgress(40);
Thread.Sleep(164);
bgWorker.ReportProgress(50);
Thread.Sleep(164);
bgWorker.ReportProgress(70);
Thread.Sleep(164);
bgWorker.ReportProgress(95);
Thread.Sleep(164);
bgWorker.ReportProgress(100);
}
private void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.progressBar1.Value = e.ProgressPercentage;
}
private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
showCrystalReport();
}
private void button1_Click(object sender, EventArgs e)
{
bgWorker.ProgressChanged +=
new ProgressChangedEventHandler(bgWorker_ProgressChanged);
bgWorker.WorkerReportsProgress =
true;
bgWorker.RunWorkerAsync();
}
private void showCrystalReport()
{
CrystalReport1 c = new CrystalReport1();
Reportds d = new Reportds();
d.Tables[0].Merge(ds.Tables[
"tab"]);
frmCryst f = new frmCryst();
c.SetDataSource(d);
f.crystRep.ReportSource = c;
f.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}

Login to add your contents and source code to this article
share this article :
post comment
 

This Article is Very Useful for All Programers that Learn Crystal Report.

Posted by Mirmahboob Hoseini Jan 16, 2010
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Gauge for SharePoint
Become a Sponsor