Hello
When saving the image, instead of going to the database file with the right size, it goes like this:
CodeinsideVisualStudio:
privatevoidbutton1_Click_1(objectsender,EventArgse){OpenFileDialogdialog=newOpenFileDialog();dialog.Filter="JPEG Files(*.jpg)|*.jpg";
if (dialog.ShowDialog() == DialogResult.OK)
{
string foto = dialog.FileName.ToString();
textBox1.Text = foto;
pictureBox1.ImageLocation = foto;
}
}
private void button3_Click(object sender, EventArgs e)
{
byte[] img = new byte[0];
FileStream Stream = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read);
BinaryReader binary = new BinaryReader(Stream);
img = binary.ReadBytes((int)Stream.Length);
string comando = "INSERT INTO ibagen(img) VALUES('" + img.ToArray() + "')";
MySqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = comando;
try
{
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Imagem enviada com sucesso!");
}catch(Exception ex)
{
MessageBox.Show(ex.Message);
}finally
{
con.Close();
}
}
I do not know what else to do, I tried to convert the "image" that was to the database, and here it comes: