我使用 C# 将图像插入 Mysql 数据库。字节数组的长度是 51115。但是,当我在数据库中检查时,字段 IMage (Long Blob) 的长度只有 13 个字节。有什么问题?请帮我!
private void saveBtn_Click(object sender, EventArgs e)
{
try
{
Image img = imgBox.Image;
byte[] arr;
ImageConverter converter = new ImageConverter();
arr = (byte[])converter.ConvertTo(img, typeof(byte[]));
MessageBox.Show(arr.Length.ToString()); // 51115
string connectionString = "server=localhost;user id=root;password=xrayadmin;database=xraydatabase";
string query = "INSERT INTO imagedatabase(IDPatient,Image,DiagnosisDoctor,DiagnosisDate) VALUES('" + Convert.ToInt32(labPatID.Text) + "','" +
arr + "','" + labDocUser.Text + "','" + DateTime.Now.ToString("dd / MM / yyyy") + "')";
MySqlConnection MysqlConnection = new MySqlConnection(connectionString);
MySqlCommand MysqlCmd = new MySqlCommand(query, MysqlConnection);
MySqlDataReader DataReader;
MysqlConnection.Open();
DataReader = MysqlCmd.ExecuteReader();
MessageBox.Show("Save Data");
while (DataReader.Read())
{
}
MysqlConnection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}