Item Property (SqlParameterCollection)
The following example creates a
SqlParameterCollection, adds instances of
SqlParameter to the collection, displays the names of its
SqlParameter objects, and then clears the collection.
public void CreateSqlParamColl(SqlCommand myCommand) {
SqlParameterCollection myParamCollection = myCommand.Parameters;
myParamCollection.Add("DeptNo", SqlType.Integer);
myParamCollection.Add("DName", SqlType.VarChar);
myParamCollection.Add("Loc", SqlType.VarChar);
string myParamNames = "";
for (int i=0; i < myParamCollection.Count; i++)
myParamNames += myParamCollection[i].ToString() + "\n";
MessageBox.Show(myParamNames);
myParamCollection.Clear();
}
Public Sub CreateSqlParamColl(myCommand As SqlCommand)
Dim myParamCollection As SqlParameterCollection = myCommand.Parameters
myParamCollection.Add("DeptNo", SqlType.Integer)
myParamCollection.Add("DName", SqlType.VarChar)
myParamCollection.Add("Loc", SqlType.VarChar)
Dim myParamNames As String = ""
Dim i As Integer
For i = 0 To myParamCollection.Count - 1
myParamNames += myParamCollection(i).ToString() + ControlChars.Cr
Next i
MessageBox.Show(myParamNames)
myParamCollection.Clear()
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2