Description:
Connector/NET 1.0.8 is not backwards compatible with Connector/NET 1.0.7 when it comes to prepared statements. With 1.0.7 you could add a parameter for a prepared statement just using the number of the parameter. With 1.0.8 you need to add it using a question mark before the number of the parameter. For example, the following works in 1.0.7:
MySqlParameter parm = command.get_Parameters().Add("1", MySqlDbType.VarString);
but must be changed to the following in 1.0.8:
MySqlParameter parm = command.get_Parameters().Add("?1", MySqlDbType.VarString);
How to repeat:
Here's an example that works with 1.0.7 but fails with 1.0.8:
package MySQLPreparedStatement;
import MySql.Data.MySqlClient.*;
/**
* Summary description for Program
*/
public class Program
{
public static void main(String[] args)
{
String connectString = "server=tennis;database=test;user id=root;password=root";
MySqlConnection connection = new MySqlConnection(connectString);
connection.Open();
MySqlCommand command = new MySqlCommand();
command.set_Connection(connection);
command.set_CommandType(System.Data.CommandType.Text);
command.set_CommandText("select * from bdnetdata where app = ?1");
MySqlParameter parm = command.get_Parameters().Add("1", MySqlDbType.VarString);
parm.set_Direction(System.Data.ParameterDirection.Input);
parm.set_Value("BD_Unnamed_App");
parm.set_Size("BD_Unnamed_App".length());
command.Prepare();
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
int num = reader.get_FieldCount();
for (int i = 0; i < num; i++)
System.out.println(reader.get_Item(i));
}
}
}
Suggested fix:
With prepared statements, allow just the number of the parameter to be used as the parameter name.