Products Technologies Demo Docs Blog Support Company

MailMerge: Master Table and Client Tables

The MailMerge Merge method uses a DataTable as the master table, controlling how many output documents are produced. Child table fields use a dot-prefixed naming convention. Inside merge blocks, each block defines its own master table, and child relations resolve from that scope.

MailMerge: Master Table and Client Tables

The Merge method of MailMerge accepts a DataTable as a parameter. This table acts as the master table for the merge process.

MergeField names without a prefix in the template are matched to this table and doesn't require a prefix. The rows of the master table are used to create the document instances of the template. In other words: The number of resulting documents in a merge process depends on the number of records in the master table.

All relations between child tables and the master table is defined as a prefix in the merge field name concatenated with a dot:

ChildTable[.ChildTable].ColumnName

Our sample database has the following structure:

MailMerge: Master table and client tables

In case the master table is Sales_SalesOrderHeader, the merge field values for MergeFields without a prefix are coming from this table. If MergeFields have a prefix, the values are coming from related tables such as Sales_SalesOrderDetail:

Sales_SalesOrdcerDetail.ProductID

The number of records in a merge process is based on the number of records in the master table. That implies that the complete template will be populated with all records available in the master table. This is easier to understand, if the table structure is illustrated as an XML file:

<Report>
    <Sales_SalesOrderHeader>
        <SalesOrderID>1</SalesOrderID>
        <OrderDate>12-12-2014</OrderDate>
        <RevisionDate>12-12-2014</RevisionDate>
    </Sales_SalesOrderHeader>
    <Sales_SalesOrderHeader>
        <SalesOrderID>2</SalesOrderID>
        <OrderDate>11-12-2014</OrderDate>
        <RevisionDate>11-12-2014</RevisionDate>
    </Sales_SalesOrderHeader>

    <Sales_SalesOrderDetail>
        <SalesOrderID>1</SalesOrderID>
        <ProductID>3</ProductID>
        <CustomerID>12</CustomerID>
    </Sales_SalesOrderDetail>
    <Sales_SalesOrderDetail>
        <SalesOrderID>2</SalesOrderID>
        <ProductID>4</ProductID>
        <CustomerID>13</CustomerID>
    </Sales_SalesOrderDetail>
</Report>

If Sales_SalesOrderHeader is the master table, the template will be processed 2 times as there are 2 records available in the data source.

The master table is the base table for the complete report. Inside of merge blocks, the master table for this block is the merge block table. All child tables of this block table can be used inside of the merge block with the same notation. In other words: Each merge block as a new master table and relations are based on the block master table.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Reporting

The Text Control Reporting Framework combines powerful reporting features with an easy-to-use, MS Word compatible word processor. Users can create documents and templates using ordinary Microsoft Word skills. The Reporting Framework is included in all .NET based TX Text Control products including ASP.NET, Windows Forms and WPF.

See Reporting products

Related Posts

ASP.NETReportingHTML5

Creating Your First ASP.NET Reporting Application

The MailMerge and ServerTextControl components of TX Text Control .NET Server for ASP.NET enable server-side reporting in Web Forms. A template.docx merges with XML data via a button click…


ASP.NETReportingTutorial

New Online Sample: Build your First Report

A new interactive online demo walks through building a report with TX Text Control in three steps: preparing JSON data in a live editor, creating a template with merge fields and repeating blocks,…


ReportingDocumentationReportingCloud

Create your First Document with ReportingCloud

ReportingCloud documentation now includes interactive tutorials for creating documents without code. Users enter an API key, choose a format such as PDF or DOCX, customize the merge data payload,…


CloudReportingMail Merge

MailMerge: Starting Each Merge Block on a New Page

Merge blocks in TX Text Control repeat based on matching data rows. Applying ParagraphFormat.PageBreakBefore to the first paragraph of a block forces each repetition onto a new page. Section…


ReportingTutorialWeb API

Using MailMerge with JSON Data

Merge document templates with JSON data using TX Text Control MailMerge by converting nested JSON strings into DataSet objects via Newtonsoft.Json. The JSON is first transformed to XML, then…

Share on this blog post on: