simple MySQL binary data inserting

断了今生、忘了曾经 提交于 2021-01-27 21:03:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!