获取 DB2Parameter 在集合中的位置。
| 名称 | 描述 |
|---|---|
| IndexOf(Object) As Integer Implements IList.IndexOf | 获取具有指定参数名的 DB2Parameter 对象在集合中的位置。 |
| IndexOf(String) As Integer Implements IDataParameterCollection.IndexOf | 获取具有特定参数名的 DB2Parameter 在集合中的位置。 |
[Visual Basic, C#] 以下示例在 DB2ParameterCollection 中搜索带有给定 DB2Parameter.Name 的 DB2Parameter。如果该参数存在,那么示例将显示它的名称和下标。如果该参数不存在,那么示例将显示错误。此示例假定已经创建了 DB2ParameterCollection 集合。
[Visual Basic]
Public Sub SearchDB2Params()
' ...
' create DB2ParameterCollection myParameters
' ...
If Not myParameters.Contains("Description") Then
MessageBox.Show("ERROR: no such parameter in the collection")
Else
MessageBox.Show("Name: " & myParameters("Description").ToString() & _
"Index: " & myParameters.IndexOf("Description").ToString())
End If
End Sub 'SearchDB2Params
[C#]
public void SearchDB2Params() {
// ...
// create DB2ParameterCollection myParameters
// ...
if (!myParameters.Contains("Description"))
MessageBox.Show("ERROR: no such parameter in the collection");
else
MessageBox.Show("Name: " + myParameters["Description"].ToString() +
"Index: " + myParameters.IndexOf("Description").ToString());
}