Click here to Skip to main content
15,887,404 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello there,
I have created an App in C#, wherein:

I wan to update Crystal Report dynamically.

For this purpose,
1. I have created a DataSet (item in solution) 01 - Items.PNG - Google Drive[^]

2. Added/Defined Tables, one of these tables is "PersonalInfo" 02 - DataTabe (from DataSet).PNG - Google Drive[^]

3. In File Explorer of Crystal Report Source/Database Fields was/were defined (from Database Expert) 03 - DatabaseField.PNG - Google Drive[^]

4. Added Crystal Report to solution and Formatted/Designed my Crystal Report as per my requirements. 04.01 - Report (2).PNG - Google Drive[^]

5. Added Code to Form2

When I run the app, and click to generate PGF, it show nothing from DataTable/DataSet but blank filed and only the headers.


What I have tried:

C#
ReportDocument repDoc;
SalariesDataSet salariesDataSet;

DataTable tblPersonalInfo;

private void Form2_Load(object sender, EventArgs e)
{
    salariesDataSet = new SalariesDataSet();
    tblPersonalInfo = salariesDataSet.Tables["PersonalInfo"];

}



private void button1_Click(object sender, EventArgs e)
{
   tblPersonalInfo.Rows.Add("AWKUM01", "Kashif Ahmad Khan", "My Father Name", "05.10.1988", "1710142640743", "03369986664", "username01@example.com", "245654285");
tblPersonalInfo.Rows.Add("AWKUM02", "Employee Two", "Father Name 02", "21.05.1988", "1610242644333", "03119686735", "username02@example.com", "5554253212");
    tblPersonalInfo.Rows.Add("AWKUM03", "Emp Three", "Father Name 03", "10.05.1990", "1710142640743", "045966452", "username03@example.com", "455253384");

    using (repDoc = new ReportDocument())
    {
        for (int i = 0; i < tblPersonalInfo.Rows.Count; i++)
        {
            CrystalReport2 cryRpt = new CrystalReport2();

            cryRpt.SetDataSource(tblPersonalInfo);

            repDoc.Load(AppDomain.CurrentDomain.BaseDirectory + "\\CrystalReport2.rpt");
            repDoc.ExportToDisk(ExportFormatType.PortableDocFormat, AppDomain.CurrentDomain.BaseDirectory + "\\SalarySlip" + i + ".pdf");
        }
    }  
}
Posted

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900