0
votes

My requirement is to generate/print mark-sheet of all student of a particular class at a single click, in crystal report.

WHEN I USED For loop then it shows only the last record/page of the report.

AND My code is

private void btnGenerate_Click(object sender, EventArgs e) {

        try
        {
            axCrystalActiveXReportViewer1.ReportSource = null;

            ReportDocument cryRpt = new ReportDocument();
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables;


            crConnectionInfo.ServerName = Configuration.ServerName;
            crConnectionInfo.DatabaseName = Configuration.DataBaseName;
            crConnectionInfo.UserID = Configuration.Server_userName;
            crConnectionInfo.Password = Configuration.Server_password;



            CrTables = cryRpt.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }

           for(int i=0; i<=x; i++)
            {
                DataSet ds_ViewTermMarkSheet = new DataSet();
                Hashtable htViewTermMarkSheet = new Hashtable();

                htViewTermMarkSheet.Add("@Year", txtYear.Text);
                htViewTermMarkSheet.Add("@Faculty", cboFaculty.Text);
                htViewTermMarkSheet.Add("@Level", cboClass.Text);
                htViewTermMarkSheet.Add("@Section", cboSection.Text);
                htViewTermMarkSheet.Add("@term", cboTerm.Text);
                htViewTermMarkSheet.Add("@CRN",.ToString());

                DbOperations _dbAccess = new DbOperations();
                _dbAccess.selectStoredProcedure(ds_ViewTermMarkSheet, "spSelectExamView_Exam_TermWiseMarkSheet", htViewTermMarkSheet, "Marks");





            cryRpt.SetDataSource(ds_ViewTermMarkSheet.Tables["Marks"]);
           }



                axCrystalActiveXReportViewer1.Refresh();


            cryRpt.Close();

        }
        catch (Exception ex)
        {
            MessageBox.Show("Mark Sheet generation was not successful.\r" + ex.Message, "Error!");
        }
    }

how can i append multiple marksheet at once and print them at once??

2

2 Answers

0
votes

Your code will loop and set the datasource multiple times , but will refresh the report just for the last one. You need to move the refresh indice the loop andalso print the report there:

        cryRpt.SetDataSource(ds_ViewTermMarkSheet.Tables["Marks"]);
        axCrystalActiveXReportViewer1.Refresh();
        // print the rpeort
       }

The right way to handle this is to create a report, which shows information about all the students. You can group by student ID or name and set a new page after the group. Then print this report ( just 1 time).

0
votes

You have to call :

cryRpt.SetDataSource(ds_ViewTermMarkSheet.Tables["Marks"]); 

..from out side the for loop

In the for loop populate your datatable with all the information you needed. and then from out side the loop call the SetDataSource() method.

Cheers