Data Sources
Whether your data lives in business objects, a database, a JSON file or an XML export, MailMerge can merge it, and a template works with every kind as long as the names and the hierarchy match. Each kind of data has its own merge method, can be offered in the Reporting tab for template design and, for databases, can be described by a data source configuration file, a feature of Windows Forms applications.
How Data Reaches a Template
Two classes handle data, for two purposes:
MailMergemerges it. Its merge methods take the data and fill the template in aTextControlorServerTextControl.DataSourceManagerdescribes it. The DataSourceManager of the Reporting tab loads the same kinds of data, analyzes their tables, columns and relations and fills the drop-downs that users insert fields and blocks with.
Every kind of data ends up as tables: the records you merge form the master table, whose columns fill merge fields, and nested collections or related tables fill merge blocks. Overview explains this model.
| Data | Merge with | Load for design with | Page |
|---|---|---|---|
| A business object or a collection of them, dictionaries | MergeObject, MergeObjects | LoadSingleObject, LoadObjects, LoadAssembly | Objects and Collections |
A DataTable, or a DataSet with relations | Merge | LoadDataTable, LoadDataSet, a database connection | DataSets and DataTables |
| A JSON string | MergeJsonData | LoadJson | JSON and XML |
| An XML file or string | Merge, after DataSet.ReadXml | LoadXmlFile, LoadXmlString | JSON and XML |
| A database described by a configuration file | Merge() with ReportDataSourceConfigFile | LoadDataSourceConfig | Data Source Configuration Files |
Data Sources in the Reporting Tab
Users choose the data for template design in the Select Data Source drop-down of the Reporting tab, which connects a database or opens an XML file, a JSON file or an assembly, as Data Source in Reporting Ribbon and Dialog Boxes shows. Your code loads data for the users instead, typically in the Load event of the form, as the Getting Started tutorial Create a Template does with invoice.json. The data used for design only needs the structure of the real data; the template is merged later with any data of that structure.
Choose a Data Source
| If your data is | Use |
|---|---|
| Classes of your application, or data you query into objects | Business objects: Objects and Collections |
| Rows from a database in ADO.NET form | A DataSet with relations: DataSets and DataTables |
| The response of a web service, a file from another system | JSON or XML: JSON and XML |
| A database that templates should query by themselves | A configuration file: Data Source Configuration Files |
Business objects and JSON are the most direct choices for new applications: they carry the hierarchy of the document without extra relations.
Pages in This Section
- Objects and Collections: merge business objects, dictionaries and anonymous objects, control names with attributes.
- DataSets and DataTables: merge tables with relations and connect a database in the Reporting tab.
- JSON and XML: merge JSON, handle invalid JSON, read XML into a
DataSetand set parsing cultures. - Data Source Configuration Files: save a database connection with its relations and merge templates with it.