我正在使用以下代码插入 blob 字段:
MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlCommand cmd;
conn = new MySql.Data.MySqlClient.MySqlConnection();
cmd = new MySql.Data.MySqlClient.MySqlCommand();
string SQL;
int FileSize;
byte[] rawData;
FileStream fs;
conn.ConnectionString = "server=192.168.1.104;uid=root;" +
"pwd=root;database=cady234;";
fs = new FileStream(@"d:\Untitled.gif", FileMode.Open, FileAccess.Read);
FileSize = (int)fs.Length;
rawData = new byte[FileSize];
fs.Read(rawData, 0, FileSize);
fs.Close();
conn.Open();
string strFileName = "test name";
SQL = "INSERT INTO file (file_name, file_size, file) VALUES ('" + strFileName + "', "+FileSize+", '"+rawData+"')";
cmd.Connection = conn;
cmd.CommandText = SQL;
cmd.ExecuteNonQuery();
conn.Close();
插入没问题,但使用“在查看器中打开值”时图像未显示: