static void GetMyBinaryString(MySqlConnection connection) {
MySqlCommand insertCommand = new MySqlCommand("INSERT INTO autotest.simple_types (f_binary, f_varbinary) VALUES (:p1, :p2)", connection);
Encoding encoding = Encoding.Unicode;
byte[] buffer1 = encoding.GetBytes("test1");
byte[] buffer2 = encoding.GetBytes("test2");
insertCommand.Parameters.Add("p1", new MySqlBinaryString(buffer1, encoding));
insertCommand.Parameters.Add("p2", new MySqlBinaryString(buffer2, encoding));
insertCommand.ExecuteNonQuery();
MySqlCommand selectCommand = new MySqlCommand("SELECT f_binary, f_varbinary FROM autotest.simple_types", connection);
using (MySqlDataReader reader = selectCommand.ExecuteReader())
while (reader.Read())
for (int i = 0; i < reader.FieldCount; ++i) {
MySqlBinaryString value = reader.GetMySqlBinaryString(i);
value.Encoding = encoding;
Console.WriteLine(value);
}
}