In this post we will discuss about What is the difference between main data source and secondary data sources in infopath 2010 in SharePoint 2010.
Also you can check out my previous posts on:
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 are bound to those fields. There are 2 types of data sources:
- 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:
A main data source 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 form template.
When you create a form template, Microsoft Office InfoPath automatically creates the main data source.
Secondary data sources:
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
Some difference between Main data source and Secondary data sources:
- Secondary data sources are optional in a form template. But all form templates must have a 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 is 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. See more here
Programmatically access data sources:
Main Data Source:
Below is the code to access main data source using C#.Net code in infopath 2010:
XPathNavigator mds = MainDataSource.CreateNavigator();
Secondary data source:
Below is the code to access secondary data source using C#.Net code in infopath 2010:
XPathNavigator sds = DataSources["dataconnectionName"].CreateNavigator();
XPathNavigator sds = DataSources["Employees"].CreateNavigator();
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.
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.