This documentation is archived and is not being maintained.

SqlParameterCollection.Clear Method

Removes all items from the collection.

[Visual Basic]
Public Overridable Sub Clear() Implements IList.Clear
[C#]
public virtual void Clear();
[C++]
public: virtual void Clear();
[JScript]
public function Clear();

Implements

IList.Clear

Example

[Visual Basic, C#, C++] The following example exports the collection to an array of SqlParameter objects, removes the objects from the collection, and returns true if the parameters are no longer persisting. This example assumes that a SqlParameterCollection has already been created by a SqlCommand.

[Visual Basic] 
Public Function ExportAndClear() As Boolean
    ' ...
    ' create SqlCommand myCmd
    ' ...
    Dim myParamArray(myCmd.Parameters.Count - 1) As SqlParameter
    myCmd.Parameters.CopyTo(myParamArray, 0)
    myCmd.Parameters.Clear()
    Return True
End Function 'ExportAndClear

[C#] 
public bool ExportAndClear() {
    // ...
    // create SqlCommand myCmd
    // ...
    SqlParameter[] myParamArray = new SqlParameter[myCmd.Parameters.Count - 1];
    myCmd.Parameters.CopyTo(myParamArray, 0);
    myCmd.Parameters.Clear();
    return true;
 }

[C++] 
public:
bool ExportAndClear() {
    // ...
    // create SqlCommand myCmd
    // ...
    SqlParameter* myParamArray[] = new SqlParameter*[myCmd->Parameters->Count - 1];
    myCmd->Parameters->CopyTo(myParamArray, 0);
    myCmd->Parameters->Clear();
    return true;
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

SqlParameterCollection Class | SqlParameterCollection Members | System.Data.SqlClient Namespace

Show: