This documentation is archived and is not being maintained.

OdbcCommand.Prepare Method

Creates a prepared or compiled version of the command at the data source.

Namespace:  System.Data.Odbc
Assembly:  System.Data (in System.Data.dll)

public override void Prepare()

Implements

IDbCommand.Prepare()

ExceptionCondition
InvalidOperationException

The Connection is not set.

-or-

The Connection is not [!:System.Data.Odbc.OdbcConnection.Open].

The Prepare method calls the ODBC SQLPrepare function. Depending on the capabilities of the underlying ODBC driver and data source, parameter information such as data types may be checked when the statement is prepared, if all parameters have been bound, or when it is executed if not all parameters have been bound. For maximum interoperability, an application should unbind all parameters that applied to a previous SQL statement before preparing a new SQL statement on the same OdbcCommand. This prevents errors that are caused by previous parameter information being applied to the new SQL statement.

If you call an Execute method after you call Prepare, any parameter value that is larger than the value specified by the [!:System.Data.Odbc.OdbcParameter.Size] property is automatically truncated to the original specified size of the parameter, and no truncation errors are returned.

Output parameters (whether prepared or not) must have a user-specified data type. If you specify a variable length data type, you must also specify the maximum [!:System.Data.Odbc.OdbcParameter.Size].

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: