Search code examples
c#.netrdlcdynamic-rdlc-generation

Add records from Details Table after respective Master Table record in Report


I have two tables for Billing, one Bill_Master and other is Bill_Detail. The records in both tables are as follows...

**BILL_MASTER**
id    party    bill_amount
1      abc      500
2      def      600

**BILL_DETAILS**
mstr_id    sr_no    perticular    amount
 1          1        lunch box     100
 1          2        water bag     400
 2          1        pencil boxes  300
 2          2        a4 papers     100
 2          3        staple pins   200

Now I want to make a RDLC as per below

**RESULT_TABLE**
mstr_id    party      billamount
 1         abc           500
           lunch box     100
           water bag     400
 2         def           600
           pencil boxes  300
           a4 papers     100
           staple pins   200

My database is SQLite. How to do it?


Solution

  • First of all Do a Sql Join to get the results from the two tables in a DataSet .Create a report (EmptyReport) right click report and Edit . Add this section inside <DataSets> tag.

    <DataSet Name="DataSet1">
      <Fields>
        <Field Name="mstr_id">
          <DataField>mstr_id</DataField>
          <rd:TypeName>System.Int32</rd:TypeName>
        </Field>
        <Field Name="party">
          <DataField>party</DataField>
          <rd:TypeName>System.Int32</rd:TypeName>
        </Field>
        <Field Name="billamount">
          <DataField>billamount</DataField>
          <rd:TypeName>System.Int32</rd:TypeName>
        </Field>
    


    And then Feed that DataSource to Rdlc Report like this:

    reportViewer1.LocalReport.ReportPath = ("testReport.rdlc");
    reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", ds.Tables[0]));
    reportViewer1.RefreshReport();
    

    On the report after you have done the above. Drag drop the columns in a List. And set GroupBy mstr_id.

    Any thing else let me know.