Prepare Method

MySQL Connector.Net

Collapse image Expand Image Copy image CopyHover image
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.8.4.0

Syntax

C#
public override void Prepare()
Visual Basic
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.
Visual Basic Copy imageCopy
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
C# Copy imageCopy
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