Table of Contents

Class DuckDBCommand

Namespace
DuckDB.NET.Data
Assembly
DuckDB.NET.Data.dll
public class DuckDBCommand : DbCommand, IComponent, IDbCommand, IDisposable, IAsyncDisposable
Inheritance
DuckDBCommand
Implements
Inherited Members

Constructors

DuckDBCommand()

public DuckDBCommand()

DuckDBCommand(string)

public DuckDBCommand(string commandText)

Parameters

commandText string

DuckDBCommand(string, DuckDBConnection)

public DuckDBCommand(string commandText, DuckDBConnection connection)

Parameters

commandText string
connection DuckDBConnection

Properties

CommandText

Gets or sets the text command to run against the data source.

public override string CommandText { get; set; }

Property Value

string

The text command to execute. The default value is an empty string ("").

CommandTimeout

Gets or sets the wait time (in seconds) before terminating the attempt to execute the command and generating an error.

public override int CommandTimeout { get; set; }

Property Value

int

The time in seconds to wait for the command to execute.

CommandType

Gets or sets how the CommandText property is interpreted.

public override CommandType CommandType { get; set; }

Property Value

CommandType

One of the enumeration values that specifies how a command string is interpreted. The default is Text.

DbConnection

Gets or sets the DbConnection used by this DbCommand.

protected override DbConnection? DbConnection { get; set; }

Property Value

DbConnection

The connection to the data source.

DbParameterCollection

Gets the collection of DbParameter objects.

protected override DbParameterCollection DbParameterCollection { get; }

Property Value

DbParameterCollection

The parameters of the SQL statement or stored procedure.

DbTransaction

Gets or sets the DbTransaction within which this DbCommand object executes.

protected override DbTransaction? DbTransaction { get; set; }

Property Value

DbTransaction

The transaction within which a command object of a .NET data provider executes. The default value is a null reference (Nothing in Visual Basic).

DesignTimeVisible

Gets or sets a value indicating whether the command object should be visible in a customized interface control.

public override bool DesignTimeVisible { get; set; }

Property Value

bool

true, if the command object should be visible in a control; otherwise false. The default is true.

Parameters

public virtual DuckDBParameterCollection Parameters { get; }

Property Value

DuckDBParameterCollection

UpdatedRowSource

Gets or sets how command results are applied to the DataRow when used by the Update method of a DbDataAdapter.

public override UpdateRowSource UpdatedRowSource { get; set; }

Property Value

UpdateRowSource

One of the enumeration values that indicates how command results are applied. The default is Both unless the command is automatically generated. Then the default is None.

UseStreamingMode

A flag to determine whether to use streaming mode or not when executing a query. Defaults to false. In streaming mode DuckDB will use less RAM but query execution might be slower. Applies only to queries that return a result-set.

public bool UseStreamingMode { get; set; }

Property Value

bool

Remarks

Streaming mode uses duckdb_execute_prepared_streaming and duckdb_stream_fetch_chunk, non-streaming (materialized) mode uses duckdb_execute_prepared and duckdb_result_get_chunk.

Methods

Cancel()

Attempts to cancel the execution of a DbCommand.

public override void Cancel()

CreateDbParameter()

Creates a new instance of a DbParameter object.

protected override DbParameter CreateDbParameter()

Returns

DbParameter

A DbParameter object.

ExecuteDbDataReader(CommandBehavior)

Executes the command against its connection, returning a DbDataReader which can be used to access the results.

protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)

Parameters

behavior CommandBehavior

An instance of CommandBehavior, specifying options for command execution and data retrieval.

Returns

DbDataReader

A DbDataReader object.

Exceptions

DbException

An error occurred while executing the command.

ArgumentException

An invalid CommandBehavior value.

ExecuteNonQuery()

Executes the command against its connection object, returning the number of rows affected.

public override int ExecuteNonQuery()

Returns

int

The number of rows affected.

ExecuteReader()

public DuckDBDataReader ExecuteReader()

Returns

DuckDBDataReader

ExecuteReader(CommandBehavior)

public DuckDBDataReader ExecuteReader(CommandBehavior behavior)

Parameters

behavior CommandBehavior

Returns

DuckDBDataReader

ExecuteScalar()

Executes the command and returns the first column of the first row in the first returned result set. All other columns, rows and result sets are ignored.

public override object? ExecuteScalar()

Returns

object

The first column of the first row in the first result set.

Prepare()

Creates a prepared (or compiled) version of the command on the data source.

public override void Prepare()