DataConnection.Execute 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
根据从中调用数据连接的 ConnectionTypeConnection 类,使用以声明形式为已提交数据、查询参数或要检索的数据定义的值,在数据连接上执行提交或查询操作。
public:
abstract void Execute();
public abstract void Execute ();
abstract member Execute : unit -> unit
Public MustOverride Sub Execute ()
例外
执行操作失败。
传递给此方法的参数是 null 引用, (Visual Basic) 中没有。
传递给此方法的参数无效。 例如,它们的类型或格式有误。
未映射到等效的托管代码异常的非托管代码引发了结构化异常处理程序 (SEH) 错误。 有关详细信息,请在 MSDN Library 上搜索“unmanaged exceptions”和“Structured Exception Handling”。
示例
在以下示例中,使用 ADOQueryConnection 类的 Command 属性更新数据连接的 SQL 命令文本后,类的 DataConnectionExecute 方法用于执行查询以刷新表单中的数据。
public void RefreshData_Clicked(object sender, ClickedEventArgs e)
{
// Get the Employees connection from the
// DataConnections collection.
AdoQueryConnection myAdoQueryConnection =
(AdoQueryConnection)(this.DataConnections["Employees"]);
// Get the employee's ID from the EmpID field in
// the main data source.
XPathNavigator myNav =
CreateNavigator().SelectSingleNode("/my:myFields/my:EmpID",
NamespaceManager);
// Assign the value from the field to a variable.
string employeeID = myNav.InnerXml;
// Change the SQL command for Employees connection to retrieve
// the record of the Employee's ID entered by the user.
myAdoQueryConnection.Command =
"select * from [Employees] where [EmployeeID] = " + employeeID;
// Execute the updated command against the data connection to
// refresh the data.
myAdoQueryConnection.Execute();
}
Public Sub RefreshData_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
' Get the Employees connection from the
' DataConnections collection.
Dim myAdoQueryConnection As AdoQueryConnection = _
DirectCast(Me.DataConnections("Employees"), AdoQueryConnection)
' Get the employee's ID from the EmpID field in
' the main data source.
Dim myNav As XPathNavigator = _
CreateNavigator().SelectSingleNode("/my:myFields/my:EmpID", _
NamespaceManager)
Dim employeeID As String = myNav.InnerXml
' Change the SQL command for Employees connection to retrieve
' the record of the Employee's ID entered by the user.
myAdoQueryConnection.Command = _
"select * from [Employees] where [EmployeeID] = " + employeeID
' Execute the updated command against the data connection to
' refresh the data.
myAdoQueryConnection.Execute()
End Sub
注解
设计表单模板时,可以使用“数据”选项卡上的“提交操作”命令来定义要提交到的目标,以及存储在表单模板文件的解决方案定义文件 (.xsf) 中的相关设置。 还可以使用“数据”选项卡上的“数据连接”命令来定义提交或接收数据的设置,这些设置存储在解决方案定义文件 (.xsf) 中。 使用 方法使用这些 Execute() 声明性定义的设置对数据连接执行提交或查询操作。
代表数据连接的所有类都继承 DataConnection.Execute 方法,该方法作为该类的一个继承方法(如 EmailSubmitConnection.Execute() 方法)公开。 根据继承类所代表的数据连接的类型,Execute 方法将执行适用于该连接的声明提交或查询操作。
AdoQueryConnection | 查询 |
AdoSubmitConnection | 提交 |
BdcQueryConnection | 查询 |
BdcSubmitConnection | 提交 |
EmailSubmitConnection | 提交 |
FileQueryConnection | 查询 |
FileSubmitConnection | 提交 |
SharePointListRWQueryConnection SharepointListQueryConnection注意以前版本的 InfoPath 中使用的类已弃用。 | 查询 |
WebServiceConnection | 提交或查询 |
此成员只能由与当前打开的表单在相同域中运行的表单访问,或者由已授予跨域权限的表单访问。
可以通过 Microsoft InfoPath Filler 或 Web 浏览器内打开的表单中运行的代码访问此类型或成员。