c# загрузка Image файла через datagridview в базу данных
создаю локальное приложение (регистратор писем) есть база данных MySql, туда грузится общие данные, в том числе отсканированные документы, при загрузки Image файла через DataGridview в базу данных через приложение в Datagrid-е вылазит такая ошибка 
вот собственно код
private void button2_Click(object sender, EventArgs e)
{
con.Open();
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
int id = Convert.ToInt32(textBox1.Text);
byte[] img = ms.ToArray();
string sql = "insert into giris(tb, register_date, register_number, name_organization, description, image) Values ('" + textBox1.Text + "', '" + dateTimePicker1.Text + "', '" + textBox2.Text + "', '" + textBox3.Text + "', '" + textBox4.Text + "', '" +pictureBox1.Text + "')";
MySqlCommand command = new MySqlCommand(sql, con);
command.ExecuteNonQuery();
con.Close();
MessageBox.Show("OK");
textBox1.Text = string.Empty;
dateTimePicker1.Text = string.Empty;
textBox2.Text = string.Empty;
textBox3.Text = string.Empty;
textBox4.Text = string.Empty;
spisok();
}
// открывает файл для загрузки
private void buttonbtnLoadPhoto_Click(object sender, EventArgs e)
{
OpenFileDialog opf = new OpenFileDialog();
opf.Filter = "Choose Image(*.jpg; *.png; *.gif)|*.jpg; *.png; *.gif";
if (opf.ShowDialog() == DialogResult.OK)
{
// pictureBox2pbxPhoto.Image = Image.FromFile(opf.FileName);
// pictureBox2pbxPhoto.Image = Image.FromFile(opf.FileName);
pictureBox1.Image = Image.FromFile(opf.FileName);
}
}
Ответы (1 шт):
Автор решения: Blackmeser
→ Ссылка
byte[] img = ms.ToArray();
strig sql = $"insert into giris(tb, register_date, register_number, name_organization, description, img_bytelength, image) Values (@tb, @register_date, @register_number, @name_organization, @description, @img_bytelength, @image)";
MySqlCommand cmd = new MySqlCommand(sql, con);
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("tb", textBox1.Text);
cmd.Parameters.AddWithValue("register_date", dateTimePicker1.Text);
cmd.Parameters.AddWithValue("register_number", textBox2.Text);
cmd.Parameters.AddWithValue("name_organization", textBox3.Text);
cmd.Parameters.AddWithValue("description", textBox4.Text);
cmd.Parameters.AddWithValue("img_bytelength", img?.Length ?? 0);
cmd.Parameters.AddWithValue("image", img);
cmd.ExecuteNonQuery();