using System; using System.Text; using MySql.Data.MySqlClient; using MySql.Data.Types; class MysqlTest { public static void Main( string[] arg ) { string connectString = "Database=test;Charset=utf8;Compress=false;Convert Zero Datetime=true"; MySqlConnection con = new MySqlConnection( connectString ); con.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = con; cmd.CommandText = "DROP TABLE IF EXISTS t1"; cmd.ExecuteNonQuery(); cmd.CommandText = @"CREATE TABLE t1 ( id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, dt DATETIME, ch VARCHAR(255) CHARACTER SET utf8, bn VARBINARY(255), tx TEXT CHARACTER SET utf8 )" ; cmd.ExecuteNonQuery(); cmd.CommandText = "INSERT INTO t1 (dt,ch,bn,tx) VALUES(?dt,?ch,?bn,?tx)"; cmd.Parameters.Clear(); cmd.Parameters.Add( "?dt", MySqlDbType.DateTime ); cmd.Parameters.Add( "?ch", MySqlDbType.VarChar ); cmd.Parameters.Add( "?bn", MySqlDbType.VarBinary ); cmd.Parameters.Add( "?tx", MySqlDbType.Text ); cmd.Prepare(); for( int i = 1; i <= 100; i++ ) { cmd.Parameters[0].Value = DateTime.Now; cmd.Parameters[1].Value = i.ToString() + new String( 'X', 200 ); cmd.Parameters[2].Value = Encoding.ASCII.GetBytes( i.ToString() + new String( 'X', 200 ) ); cmd.Parameters[3].Value = new String( 'X', 16384 ); cmd.ExecuteNonQuery(); Console.WriteLine( "insert row {0}", i ); } } }