简单的MySQL二进制数据插入 [英] simple MySQL binary data inserting
本文介绍了简单的MySQL二进制数据插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何插入字符串:
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();
如何使用varBinary插入二进制数据?
How can I insert binary data using varBinary?
推荐答案
您可以按原样插入字符串-
You can insert string as is -
command.CommandText = "INSERT INTO User (username) VALUE ('David')");
此外,您可以将数据作为十六进制值插入,使用Encoding.GetBytes方法获取分支数组,然后将字节转换为十六进制字符串(编写特殊函数),结果应如下所示-
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)");
这篇关于简单的MySQL二进制数据插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文