Microsoft Office Tutorials and References
In Depth Information
Manipulating a data source
Manipulating a data source
There may be some reason or requirement for the developer to interact with data
source from the code, that is, for manipulating a data source from managed code.
A data source is a data structure that has information about a specific data file or
database. We may have different requirements, such as manipulating data using the
data source information. Or we may need to work extensively on a process before
sending it to a data source. Anything like this may need various kinds of data source
interaction using code.
Let's take a different scenario—how Microsoft SQL Server connects to InfoPath and
manipulates the data in the InfoPath form and explain it by way of a demonstration.
Populating InfoPath form fields with data returned by the SQL database is not a
difficult task, but the scenario is how we are going to manipulate the secondary data
source from inside the InfoPath form, and how we are going to manage the data
inside the form. And this is not the only scenario to explain how the data source
data can be manipulated; this is only one of those scenarios.
Fetch node value from main data source
One of the more important processes in an InfoPath managed code solution is the
ability to retrieve a single node from an XML data source.
In our demonstration, let's take a look at how a single node value can be retrieved
using a custom function in C#, which returns the value in the string format. Here,
the FetchSingleNodeValue_MainDataSource function returns a string value when
passed a single XPath statement argument.
// Custom function to fetch the single node from the main data source.
private string FetchSingleNodeValue_MainDataSource(string xPath)
// Navigate through main data source
XPathNavigator xNode = MainDataSource.CreateNavigator().
SelectSingleNode(xPath, NamespaceManager);
return xNode.ToString();
// Button click event to call the custom function and display the
public void btn_nodevalue_Clicked(object sender, ClickedEventArgs e)
// Call the custom function to result the data.
string strResult = FetchSingleNodeValue_MainDataSource("/my:
Search JabSto ::

Custom Search