Export (0) Print
Expand All

DataAdaptersCollection Interface (Microsoft.Office.Interop.InfoPath.SemiTrust)

Contains a data adapter object corresponding to each data connection used within a Microsoft Office InfoPath 2007 form.

 

Namespace: Microsoft.Office.Interop.InfoPath.SemiTrust
Assembly: Microsoft.Office.Interop.InfoPath.SemiTrust (in microsoft.office.interop.infopath.semitrust.dll)

[CLSCompliantAttribute(false)] 
public interface DataAdaptersCollection : DataAdapters

This type is a wrapper for a coclass that is required by managed code for COM interoperability. Use this type to access the members of the COM interface implemented by this coclass. For information about the COM interface, including a link to descriptions of its members, 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:

NoteNote:

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:

A data connection used only for submitting data will correspond to one of the following data adapter object types:

The DataAdapters collection can be accessed using the DataAdapters property of the XDocument object.

NoteNote:

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 Using the InfoPath 2003 Object Model.

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;
XMLFileAdapterObject xmlFileAdapterObject;

dataAdapters = thisXDocument.DataAdapters; 
xmlFileAdapterObject = dataAdapters["form1"] as XMLFileAdapterObject;

if (xmlFileAdapterObject == null)
{
 thisXDocument.UI.Alert("The DataAdapter does not exist or is not an XMLFileAdapterObject.");
}
else
{
 thisXDocument.UI.Alert("XML file adapter" + "\n\n" + "Name: " + xmlFileAdapterObject.Name + "\n" + "QueryAllowed: " + xmlFileAdapterObject.QueryAllowed+ "\n" + "SubmitAllowed: " + xmlFileAdapterObject.SubmitAllowed+ "\n" + "FileURL: " + xmlFileAdapterObject.FileURL);

 // Perform the query.
 try
 {
  xmlFileAdapterObject.Query();
 }
 catch (Exception ex)
 {
  thisXDocument.UI.Alert("Failed to query.\n\n" + ex.Message);
 }

 // Perform the submit.
 try
 {
  xmlFileAdapterObject.Submit();
 }
 catch (Exception ex)
 {
  thisXDocument.UI.Alert("Failed to submit.\n\n" + ex.Message);
 }
}

Community Additions

ADD
Show:
© 2014 Microsoft