Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

OleDbCommand::Prepare Method ()

 

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

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

public:
virtual void Prepare() override

Exception Condition
InvalidOperationException

The Connection is not set.

-or-

The Connection is not open.

If the CommandType property is set to TableDirect, Prepare does nothing. If CommandType is set to StoredProcedure, the call to Prepare should succeed, although it may cause a no-op.

Before you call Prepare, specify the data type of each parameter in the statement to be prepared. For each parameter that has a variable length data type, you must set the Size property to the maximum size needed. Prepare returns an error if these conditions are not met.

If you call an Execute method after you call Prepare, any parameter value that is larger than the value specified by the 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 Size.

The following example creates an OleDbCommand and opens the connection. The example then prepares a stored procedure on the data source by passing a string that is an SQL SELECT statement and a string to use to connect to the data source.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show:
© 2017 Microsoft