# Data Sources

> Choose a mail merge data source in Windows Forms: business objects, DataSets, JSON, XML or configuration files, merged with MailMerge and shown in the ribbon.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > Mail Merge and Reporting > Data Sources
- **1093 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/llms-full.txt

---

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:

- **`MailMerge` merges it.** Its merge methods take the data and fill the template in a `TextControl` or `ServerTextControl`.
- **`DataSourceManager` describes it.** The [DataSourceManager](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-windows-forms-ribbon/ribbonreportingtab/datasourcemanager-property/llms-full.txt) 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](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/overview/#pre-shaped-data) explains this model.

| Data | Merge with | Load for design with | Page |
|---|---|---|---|
| A business object or a collection of them, dictionaries | [MergeObject](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/mergeobject-method/llms-full.txt), [MergeObjects](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/mergeobjects-method/llms-full.txt) | `LoadSingleObject`, `LoadObjects`, `LoadAssembly` | [Objects and Collections](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/objects/llms-full.txt) |
| A `DataTable`, or a `DataSet` with relations | [Merge](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/merge-method/llms-full.txt) | `LoadDataTable`, `LoadDataSet`, a database connection | [DataSets and DataTables](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/datasets/llms-full.txt) |
| A JSON string | [MergeJsonData](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/mergejsondata-method/llms-full.txt) | `LoadJson` | [JSON and XML](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/json-xml/llms-full.txt) |
| An XML file or string | `Merge`, after `DataSet.ReadXml` | `LoadXmlFile`, `LoadXmlString` | [JSON and XML](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/json-xml/llms-full.txt) |
| A database described by a configuration file | `Merge()` with `ReportDataSourceConfigFile` | `LoadDataSourceConfig` | [Data Source Configuration Files](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/configuration-files/llms-full.txt) |

### 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](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/ribbon-dialogs/#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](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/mail-merge/template/llms-full.txt) 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](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/objects/llms-full.txt) |
| Rows from a database in ADO.NET form | A `DataSet` with relations: [DataSets and DataTables](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/datasets/llms-full.txt) |
| The response of a web service, a file from another system | JSON or XML: [JSON and XML](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/json-xml/llms-full.txt) |
| A database that templates should query by themselves | A configuration file: [Data Source Configuration Files](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/configuration-files/llms-full.txt) |

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](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/objects/llms-full.txt): merge business objects, dictionaries and anonymous objects, control names with attributes.
- [DataSets and DataTables](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/datasets/llms-full.txt): merge tables with relations and connect a database in the Reporting tab.
- [JSON and XML](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/json-xml/llms-full.txt): merge JSON, handle invalid JSON, read XML into a `DataSet` and set parsing cultures.
- [Data Source Configuration Files](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/configuration-files/llms-full.txt): save a database connection with its relations and merge templates with it.

---

## In This Section

- [Data Source Configuration Files](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/configuration-files/llms-full.txt): Save a database connection, master table and relations as an .rdsc file in the Reporting tab and merge it with ReportDataSourceConfigFile and Merge().
- [DataSets and DataTables](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/datasets/llms-full.txt): Merge a DataTable or a DataSet with relations in Windows Forms, load it into the Reporting tab and connect a database with the DatabaseConnectionDialog.
- [JSON and XML](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/json-xml/llms-full.txt): Merge JSON with MergeJsonData and XML through DataSet.ReadXml in Windows Forms, catch ParserException and set DataSourceCulture for numbers and dates.
- [Objects and Collections](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/objects/llms-full.txt): Merge business objects, dictionaries and anonymous objects in Windows Forms with MergeObjects, DisplayName and Description attributes and ToString output.

---

## Nearby

- **Previous:** [Overview](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/overview/llms-full.txt)
- **Next:** [Objects and Collections](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/data-sources/objects/llms-full.txt)
