Report Learning Series 3

Source: Internet
Author: User

Yesterday, I wrote C # as the most basic report and manually configured the data source. This article mainly describes how to set report parameters and create sub-tables and groups.

1. Report creation Parameters

Open yesterday's project, create report rptstudent. rdlc in the report folder, drag a table, click Report-Report parameter -- add, parameter name CNO, OK

Second, add a dataset to a subreport.

Still a report -- data source -- add rptdataset_student to the report and confirm.

3. Design subreports

Add group, 1

Figure 1 group is based on classid, including the group header and group end. 2

Figure 2 set = count (Fields! Sno. Value) you can right-click the cell and select the expression -- common functions -- aggregation, select count (), select the field in the brackets of Count (), and double-click Sno. Here, by the way, grouping is actually like an aggregate function in SQL. Based on a certain grouping basis, data is divided into several groups of the same nature, just like using the shift number here, divides student data into several classes. Select a table, right-click the table, select the attribute filter, and set (= Fields! Classid. Value) = (= parameters !. CID. value) 4. settings in the main report. open the main report rptclass, drag a sub-table from the toolbox to the end of the group (it is best to merge one row of cells in the end group), rename it subrptstudent, and set the reportname of the subrptstudent control to rptstudent, right-click -- Property -- parameter -- CID value = Fields! Systemkey. value,

 

5. Write the Student Data Handler class. First, add the studnet data processing class studentdatasource. class to the datasource file, which provides a data source instance for the report.
public class StudentDataSource
{
public DataTable GetStudentData()
{
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ReportingAPP.Properties.Settings.RptDBConnectionString"].ToString());
StringBuilder cmdText = new StringBuilder();
cmdText.Append("SELECT [SystemKey] ,[Sno],[Sname],[ClassID] FROM [Student]");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(cmdText.ToString(), conn);
dt.Load(cmd.ExecuteReader());
}
catch (Exception ex)
{
}
finally
{
conn.Close();
}
return dt;
}
}
Then, add the delegate method of local event processing for the subreport to the main form. Add the following method to the main form:
        private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
e.DataSources .Add (
new ReportDataSource("RptDataSet_Student", studentDataSource.GetStudentData())
);
}
7. Add the local processing event of the subreport to the main report. In the load event of the main form, add the following statement:
Private void frmrptmain_load (Object sender, eventargs E)
{
This. rptviewmain. localreport. subreportprocessing + =
New subreportprocessingeventhandler (localreport_subreportprocessing); // if no such error exists, an error cannot be displayed in the subreport.
This. rptviewmain. localreport. reportembeddedresource = "reportingapp. Report. rptclass. rdlc ";
This. rptviewmain. localreport. CES. Add (
New reportdatasource ("rptdataset_class", datasource. getclassdata ())
);
This. rptviewmain. refreshreport ();
}
Okay, now I can't wait to press F5 ...... The Student name is not displayed... In the rptstudent table, set datasetname to rptdataset_student and select "yes" as the output data. Now. The running result is as follows:

Now let's simply summarize the processing of the Report. 1) report the rdlc file of the subreport, create parameters, select a dataset, write filter conditions, and select datasetname for the table in the report, set the output data to yes, and set the subreport format and content as needed. 2) Add the subreport control to the main report, and select the reportname of the subreport control as the newly created rdlc subreport, set parameters. 3) provides data instances for writing data to the subreport data source (corresponding datasource class) 4) provides the delegate Processing Method for writing local reports
  private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
e.DataSources .Add (
new ReportDataSource("RptDataSet_Student", studentDataSource.GetStudentData())
);
}
5) Add the subreport local processing event this. rptviewmain. localreport. subreportprocessing + =
New subreportprocessingeventhandler (localreport_subreportprocessing); it seems a little tired. Let's do it today and write a drilling report tomorrow.

Yesterday, I wrote C # as the most basic report and manually configured the data source. This article mainly describes how to set report parameters and create sub-tables and groups.

1. Report creation Parameters

Open yesterday's project, create report rptstudent. rdlc in the report folder, drag a table, click Report-Report parameter -- add, parameter name CNO, OK

Second, add a dataset to a subreport.

Still a report -- data source -- add rptdataset_student to the report and confirm.

3. Design subreports

Add group, 1

Figure 1 group is based on classid, including the group header and group end. 2

Figure 2 set = count (Fields! Sno. Value) you can right-click the cell and select the expression -- common functions -- aggregation, select count (), select the field in the brackets of Count (), and double-click Sno. Here, by the way, grouping is actually like an aggregate function in SQL. Based on a certain grouping basis, data is divided into several groups of the same nature, just like using the shift number here, divides student data into several classes. Select a table, right-click the table, select the attribute filter, and set (= Fields! Classid. Value) = (= parameters !. CID. value) 4. settings in the main report. open the main report rptclass, drag a sub-table from the toolbox to the end of the group (it is best to merge one row of cells in the end group), rename it subrptstudent, and set the reportname of the subrptstudent control to rptstudent, right-click -- Property -- parameter -- CID value = Fields! Systemkey. value,

 

5. Write the Student Data Handler class. First, add the studnet data processing class studentdatasource. class to the datasource file, which provides a data source instance for the report.
public class StudentDataSource
{
public DataTable GetStudentData()
{
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ReportingAPP.Properties.Settings.RptDBConnectionString"].ToString());
StringBuilder cmdText = new StringBuilder();
cmdText.Append("SELECT [SystemKey] ,[Sno],[Sname],[ClassID] FROM [Student]");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(cmdText.ToString(), conn);
dt.Load(cmd.ExecuteReader());
}
catch (Exception ex)
{
}
finally
{
conn.Close();
}
return dt;
}
}
Then, add the delegate method of local event processing for the subreport to the main form. Add the following method to the main form:
        private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
e.DataSources .Add (
new ReportDataSource("RptDataSet_Student", studentDataSource.GetStudentData())
);
}
7. Add the local processing event of the subreport to the main report. In the load event of the main form, add the following statement:
Private void frmrptmain_load (Object sender, eventargs E)
{
This. rptviewmain. localreport. subreportprocessing + =
New subreportprocessingeventhandler (localreport_subreportprocessing); // if no such error exists, an error cannot be displayed in the subreport.
This. rptviewmain. localreport. reportembeddedresource = "reportingapp. Report. rptclass. rdlc ";
This. rptviewmain. localreport. CES. Add (
New reportdatasource ("rptdataset_class", datasource. getclassdata ())
);
This. rptviewmain. refreshreport ();
}
Okay, now I can't wait to press F5 ...... The Student name is not displayed... In the rptstudent table, set datasetname to rptdataset_student and select "yes" as the output data. Now. The running result is as follows:

Now let's simply summarize the processing of the Report. 1) report the rdlc file of the subreport, create parameters, select a dataset, write filter conditions, and select datasetname for the table in the report, set the output data to yes, and set the subreport format and content as needed. 2) Add the subreport control to the main report, and select the reportname of the subreport control as the newly created rdlc subreport, set parameters. 3) provides data instances for writing data to the subreport data source (corresponding datasource class) 4) provides the delegate Processing Method for writing local reports
  private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
e.DataSources .Add (
new ReportDataSource("RptDataSet_Student", studentDataSource.GetStudentData())
);
}
5) Add the subreport local processing event this. rptviewmain. localreport. subreportprocessing + =
New subreportprocessingeventhandler (localreport_subreportprocessing); it seems a little tired. Let's do it today and write a drilling report tomorrow.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.