Clone Method (SqlCommand)
Creates a new object that is a copy of the current
SqlCommand instance.
'Declaration
Public Function Clone() As SqlCommand
Return Value
A new
SqlCommand object in which all property values are the same as the original.
This example shows how to clone a
SqlCommand . To make sure all the properties are inherited, one of them (CommandText) is written to the console.
public void CloneACommand()
{
SqlCommand myCommand = new SqlCommand("SELECT * FROM Test.Dept");
SqlCommand myCommand2 = (SqlCommand)myCommand.Clone();
Console.WriteLine(myCommand2.CommandText);
}
Public Sub CloneACommand()
Dim myCommand As New SqlCommand("SELECT * FROM Test.Dept")
Dim myCommand2 As SqlCommand = CType(myCommand.Clone(), SqlCommand)
Console.WriteLine(myCommand2.CommandText)
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