Prepare Method

MySQL Connector/Net

Creates a prepared version of the command on an instance of MySQL Server.

Namespace:  MySql.Data.MySqlClient
Assembly:  MySql.Data (in MySql.Data.dll) Version: 6.2.2.0

Syntax

C#
public override void Prepare()
Visual Basic (Declaration)
Public Overrides Sub Prepare
Visual C++
public:
virtual void Prepare() override

Implements

IDbCommand..::.Prepare()()()

Remarks

Prepared statements are only supported on MySQL version 4.1 and higher. Calling prepare while connected to earlier versions of MySQL will succeed but will execute the statement in the same way as unprepared.

Examples

The following example demonstrates the use of the Prepare method.
CopyVB.NET
public sub PrepareExample()
Dim cmd as New MySqlCommand("INSERT INTO mytable VALUES (@val)", myConnection)
cmd.Parameters.Add( "@val", 10 )
cmd.Prepare()
cmd.ExecuteNonQuery()

cmd.Parameters(0).Value = 20
cmd.ExecuteNonQuery()
end sub
CopyC#
private void PrepareExample()
{
MySqlCommand cmd = new MySqlCommand("INSERT INTO mytable VALUES (@val)", myConnection);
cmd.Parameters.Add( "@val", 10 );
cmd.Prepare();
cmd.ExecuteNonQuery();

cmd.Parameters[0].Value = 20;
cmd.ExecuteNonQuery();
}

See Also