dotConnect for SQL Server Documentation
Devart.Data.SqlServer Namespace / SqlConnection Class / CreateCommand Method
Example

CreateCommand Method (SqlConnection)
Creates and returns a SqlCommand object associated with the SqlConnection.
Creates and returns a SqlCommand object associated with the SqlConnection.
Syntax
'Declaration
 
Public Shadows Function CreateCommand() As SqlCommand
 

Return Value

A SqlCommand object.
Remarks
You can use this method as an alternative to common SqlCommand constructors.
Example
In this sample SqlCommand object is created. It is automatically associated with SqlConnection that created it.
public void CreateSqlCommand(string myConnString)
{
  SqlConnection myConnection = new SqlConnection(myConnString);
  SqlCommand myCommand = myConnection.CreateCommand();
  myCommand.CommandText = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')";
  myConnection.Open();
  try
  {
    myCommand.ExecuteNonQuery();
  }
  finally
  {
    myConnection.Close();
  }
}
Public Sub CreateSqlCommand(ByVal myConnString As String)
  Dim myConnection As New SqlConnection(myConnString)
  Dim myCommand As SqlCommand = myConnection.CreateCommand()
  myCommand.CommandText = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')"
  myConnection.Open()
  Try
    myCommand.ExecuteNonQuery()
  Finally
    myConnection.Close()
  End Try
End Sub
Requirements

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

See Also