System.Data.CommandBehavior Enumeration

Provides a description of the results of the query and its effect on the database.

Syntax

[System.Flags]
public enum CommandBehavior

Remarks

The System.Data.CommandBehavior values are used by the IDbCommand.ExecuteReader method of System.Data.IDbCommand and any classes derived from it.

A bitwise combination of these values may be used.

System.Data.CommandBehavior is ignored when used to define a System.Data.Sql.SqlNotificationRequest or System.Data.SqlClient.SqlDependency and should therefore not be used. Use the constructor that does not require a CommandBehavior parameter in these two cases.

Note:

Use CommandBehavior.SequentialAccess to retrieve large values and binary data. Otherwise, an OutOfMemoryException might occur and the connection will be closed.

Members

Member NameDescription
CloseConnection

When the command is executed, the associated Connection object is closed when the associated DataReader object is closed.

Default

The query may return multiple result sets. Execution of the query may affect the database state. Default sets no System.Data.CommandBehavior flags, so calling ExecuteReader(CommandBehavior.Default) is functionally equivalent to calling ExecuteReader().

KeyInfo

The query returns column and primary key information.

SchemaOnly

The query returns column information only. When using CommandBehavior.SchemaOnly, the .NET Framework Data Provider for SQL Server precedes the statement being executed with SET FMTONLY ON.

SequentialAccess

Provides a way for the DataReader to handle rows that contain columns with large binary values. Rather than loading the entire row, SequentialAccess enables the DataReader to load data as a stream. You can then use the GetBytes or GetChars method to specify a byte location to start the read operation, and a limited buffer size for the data being returned.

SingleResult

The query returns a single result set.

SingleRow

The query is expected to return a single row of the first result set. Execution of the query may affect the database state. Some .NET Framework data providers may, but are not required to, use this information to optimize the performance of the command. When you specify CommandBehavior.SingleRow with the System.Data.OleDb.OleDbCommand.ExecuteReader method of the System.Data.OleDb.OleDbCommand object, the .NET Framework Data Provider for OLE DB performs binding using the OLE DB IRow interface if it is available. Otherwise, it uses the IRowset interface. If your SQL statement is expected to return only a single row, specifying CommandBehavior.SingleRow can also improve application performance. It is possible to specify SingleRow when executing queries that are expected to return multiple result sets. In that case, where both a multi-result set SQL query and single row are specified, the result returned will contain only the first row of the first result set. The other result sets of the query will not be returned.

Requirements

Namespace: System.Data
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0, 2.0.0.0