DataAdaptersCollection Interface (Microsoft.Office.Interop.InfoPath)
Assembly: Microsoft.Office.Interop.InfoPath (in microsoft.office.interop.infopath.dll)
This type is a wrapper for a COM interface implemented by a coclass that is required by managed code for COM interoperability. To access the members specified by this interface, use the type that wraps the coclass that implements this interface. For information about that type, including usage, remarks, and examples, see DataAdapters.
Each data connection is used to retrieve data (inserted into the main data source or into a secondary data source) or to submit data.
A data connection used to retrieve data for the main data source will correspond to one of the following data adapter object types:
Note: |
|---|
An ADOAdapter object used to retrieve data for the main data source can also submit data. |
A data connection used to retrieve data for a secondary data source will correspond to one of the following data adapter object types:
ADOAdapterObject
WebServiceAdapterObject
A data connection used only for submitting data will correspond to one of the following data adapter object types:
WebServiceAdapterObject
The DataAdapters collection can be accessed using the DataAdapters property of the XDocument object.
Note: |
|---|
To use properties or methods of a data adapter object, it is necessary to cast the object returned from the DataAdaptersCollection object to the specific data adapter that it represents before you can access those members. For more information about working with data adapters, see How to: Access External Data Sources |
In the following example, an ADOAdapter object connected to the Employees table of the Northwind database is retrieved from the DataAdapters collection:
// retrieve the Employees Adapter from the DataAdapters collection ADOAdapter employeesDA = (ADOAdapter)thisXDocument.DataAdapters["Employees"];
In the following example, an XML document called "form1", available as an XML file data connection, is retrieved from the DataAdapters collection. Various properties of the connection are displayed in message boxes:
DataAdapters dataAdapters; dataAdapters = thisXDocument.DataAdapters; XMLFileAdapterObject queryXMLFile = (XMLFileAdapterObject)dataAdapters["form1"]; thisXDocument.UI.Alert("Query - XML file adapter"); thisXDocument.UI.Alert("Name: " + queryXMLFile.Name); thisXDocument.UI.Alert("QueryAllowed: " + queryXMLFile.QueryAllowed); thisXDocument.UI.Alert("SubmitAllowed: " + queryXMLFile.SubmitAllowed); thisXDocument.UI.Alert("FileURL: " + queryXMLFile.FileURL); // Perform the query. try { queryXMLFile.Query(); } catch (Exception ex) { thisXDocument.UI.Alert("Failed to query.\n\n" + ex.Message); } // Perform the submit. try { queryXMLFile.Submit(); } catch (Exception ex) { thisXDocument.UI.Alert("Failed to submit.\n\n" + ex.Message); }
Note: