3
Hello!
When saving the image, instead of going the file to the database with the right size, goes the following:
Code inside the Visual Studio:
private void button1_Click_1(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
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 don’t know what else to do, I tried to convert the "image" that went to the database, and that’s it here:
also have an example here: https://answall.com/a/207207207/69359
– Rovann Linhalis
No, nothing to do with the first
– Igor Souza
My mistake is completely different.
– Igor Souza
are right, see if the linked example helps you
– Rovann Linhalis
That’s right, my mistake is exactly this, the image does not go to the database, I don’t know why ;(
– Igor Souza