问题
I know how to insert String:
MySqlConnection connection = new MySqlConnection();
connection .Open();
MySqlCommand command = connection.CreateCommand();
command.CommandText = "INSERT INTO User ('username') VALUE ('David')");
command.ExecuteNonQuery();
connection.Close();
How can I insert binary data using varBinary?
回答1:
You can insert string as is -
command.CommandText = "INSERT INTO User (username) VALUE ('David')");
Also, you can insert data as a hex value, use Encoding.GetBytes method to get array of butes, then convert bytes to a hex string (write special function), the result should be like this -
command.CommandText = "INSERT INTO User (username) VALUE (0x4461766964)");
来源:https://stackoverflow.com/questions/9547412/simple-mysql-binary-data-inserting