DataConnection.Execute 方法
根据从中调用数据连接的 ConnectionTypeConnection 类,使用以声明形式为已提交数据、查询参数或要检索的数据定义的值,在数据连接上执行提交或查询操作。
命名空间: Microsoft.Office.InfoPath
程序集: Microsoft.Office.InfoPath(位于 Microsoft.Office.InfoPath.dll 中)
语法
声明
Public MustOverride Sub Execute
用法
Dim instance As DataConnection
instance.Execute()
public abstract void Execute()
异常
异常 | 条件 |
---|---|
WebException | 执行操作失败。 |
ArgumentNullException | 传递给此方法的参数为 空引用(无 在 Visual Basic 中)。 |
ArgumentException | 传递给此方法的参数无效。例如,它们的类型或格式有误。 |
InvalidOperationException | 对于提交操作,从 Loading 事件的事件处理程序中调用了 Execute() 方法。 |
SEHException | 未映射到等效的托管代码异常的非托管代码引发了结构化异常处理程序 (SEH) 错误。有关详细信息,请在 MSDN Library 上搜索"unmanaged exceptions"和"Structured Exception Handling"。 |
备注
设计表单模板时,可以使用"数据"选项卡上的"提交操作"命令来定义要提交到的目标,以及存储在表单模板文件的解决方案定义文件 (.xsf) 中的相关设置。还可以使用"数据"选项卡上的"数据连接"命令来定义提交或接收数据的设置,这些设置存储在解决方案定义文件 (.xsf) 中。通过使用 Execute() 方法,利用这些以声明形式定义的设置在数据连接上执行提交或查询操作。
代表数据连接的所有类都继承 DataConnection.Execute 方法,该方法作为该类的一个继承方法(如 EmailSubmitConnection.Execute() 方法)公开。根据继承类所代表的数据连接的类型,Execute 方法将执行适用于该连接的声明提交或查询操作。
类 |
操作 |
---|---|
查询 |
|
提交 |
|
查询 |
|
提交 |
|
提交 |
|
查询 |
|
提交 |
|
SharePointListRWQueryConnection 备注 在以前的 InfoPath 版本中使用的 SharepointListQueryConnection 类已被弃用。 |
查询 |
提交或查询 |
此成员只能由与当前打开的表单在相同域中运行的表单访问,或者由已授予跨域权限的表单访问。
可以通过 Microsoft InfoPath Filler 或 Web 浏览器内打开的表单中运行的代码访问此类型或成员。
示例
在下面的示例中,在使用 ADOQueryConnection 类的 Command 属性更新数据连接的 SQL 命令文本后,将使用 DataConnection 类的 Execute 方法来执行查询,以刷新表单中的数据。
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