dotConnect for PostgreSQL Documentation
Devart.Data.PostgreSql Namespace / PgSqlConnection Class / CreateCommand Method
Example

On this page
    CreateCommand Method (PgSqlConnection)
    On this page
    Creates and returns a PgSqlCommand object associated with the PgSqlConnection.
    Creates and returns a PgSqlCommand object associated with the PgSqlConnection.
    Syntax
    'Declaration
     
    Public Shadows Function CreateCommand() As PgSqlCommand
    public new PgSqlCommand CreateCommand()

    Return Value

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