Prepare (overridden)
Namespace:
System.Data.SqlClient
Assembly:
System.Data (in system.data.dll)
This
method creates a prepared version of the command on an
instance of SQL Server.
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 calling 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.
Using the Prepare method can increase the performance of
your application!
Example: How to use the Prepare
method
InvalidOperationException
This exception will occur when the Connection has not been
set or the Connection is not open
Links