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

On this page
    CreateCommand Method (SqlConnection)
    On this page
    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
    public new SqlCommand CreateCommand()

    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 sqlConnection = new SqlConnection(myConnString);
      SqlCommand sqlCommand = sqlConnection.CreateCommand();
      sqlCommand.CommandText = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')";
      sqlConnection.Open();
      try
      {
        sqlCommand.ExecuteNonQuery();
      }
      finally
      {
        sqlConnection.Close();
      }
    }
    Public Sub CreateSqlCommand(ByVal myConnString As String)
      Dim sqlConnection As New SqlConnection(myConnString)
      Dim sqlCommand As SqlCommand = sqlConnection.CreateCommand()
      sqlCommand.CommandText = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')"
      sqlConnection.Open()
      Try
        sqlCommand.ExecuteNonQuery()
      Finally
        sqlConnection.Close()
      End Try
    End Sub
    See Also