InfoPath 2010: Difference between Main and secondary data sources

This InfoPath 2010 tutorial explains, What is the difference between the main data source and secondary data sources in InfoPath 2010 in SharePoint 2010.

Every data showed in an InfoPath form, is stored in form’s data source. A data source contains fields and groups. Then suppose you add a control then this control is bound to those fields.

There are 2 types of data sources in InfoPath 2010:

  • Main data source
  • Secondary data sources

A form will have a single main data source by default and may or may not contain one or more secondary data sources.

Main data source in InfoPath 2010

The main data source in InfoPath 2010 contains the data that users add when they fill out a form that is based on the form template, such as the data that they enter into a text box.

It also contains the data from a data connection to a database or Web service, which is used to define the data source of the InfoPath 2010 form template.

When you create a form template, Microsoft Office InfoPath automatically creates the main data source.

Secondary data sources in InfoPath 2010

Secondary data sources are data sources in the form that contain data supplied through other data connections to external data sources.

The data from additional data connections is stored in secondary data sources and then displayed. You can check this article to know how to create a data connection in InfoPath 2010.

Difference between the Main data source and Secondary data sources:

  • Secondary data sources are optional in a form template. But all form templates must have the main data source.
  • A form template can have one or more secondary data sources but only a single main data source.
  • Fields and groups in a secondary data source are based on the way that data is stored in the external data source, which is connected to the form by using a data connection. These fields and groups cannot be modified by using InfoPath.
  • Unlike the main data source, secondary data sources are not saved with the form.

Data in secondary data sources are not typically submitted when the user submits a completed form. However, you can configure your form template to submit the data in the secondary data source to a Web service by using rules or to an e-mail recipient by using custom code.

Programmatically access data sources in InfoPath 2010

Main Data Source:
Below is the code to access the main data source using C#.Net code in Infopath 2010:

XPathNavigator mds = MainDataSource.CreateNavigator();

Secondary data source:
Below is the code to access the secondary data source using C#.Net code in InfoPath 2010:

XPathNavigator sds = DataSources[“dataconnectionName”].CreateNavigator();

Example:
XPathNavigator sds = DataSources[“Employees”].CreateNavigator();

Updated:
Here are few very good points I am adding which I got to know from bizsupportonline URL.

The Main InfoPath data source of a form contains the data that you want to permanently store when you save the form in InfoPath 2010 in SharePoint 2010.

You may like following InfoPath 2010 tutorials:

The secondary data source is like a temporary storage location for the data that is external to the form. The data in the secondary data sources of the form is never saved in the form when we save the form. So if you want data to be present in a form after you save, close, and re-open the form, you have to store this data in the Main data source of the InfoPath form.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>