Picturebox and datagridview

Asked

Viewed 90 times

0

Guys I’m in need of help, already managed to upload images to comics, now I have the following problem: I placed this code to select a datagridview line and fill in the respective fields.

txtIDMovie.Text = dgvMovies.Rows[e.RowIndex].Cells[0].Value.ToString();
        txtNameMovie.Text = dgvMovies.Rows[e.RowIndex].Cells[1].Value.ToString();
        txtRealizador.Text = dgvMovies.Rows[e.RowIndex].Cells[2].Value.ToString();
        txtCatMovies.Text = dgvMovies.Rows[e.RowIndex].Cells[3].Value.ToString();
        txtAnoMovie.Text = dgvMovies.Rows[e.RowIndex].Cells[4].Value.ToString();
        txtClassIdade.Text = dgvMovies.Rows[e.RowIndex].Cells[5].Value.ToString();
        txtClassIMDB.Text = dgvMovies.Rows[e.RowIndex].Cells[6].Value.ToString();
        cbFormato.Text = dgvMovies.Rows[e.RowIndex].Cells[7].Value.ToString();

For the image I used:

            byte[] bytes = (byte[])dgvMovies.Rows[e.RowIndex].Cells[8].Value;
        MemoryStream ms = new MemoryStream(bytes);
        pbCapa.Image = Image.FromStream(ms);

However, if you want to edit a field that does not have an image when selecting the line, it is an error. Is there any way to solve?

  • only test if dgvMovies.Rows[e. Rowindex]. Cells[8]. Value equals null

1 answer

0

I tested and it worked, the problem is that the database gets too slow. There is another way to save without being image?

  • you can write the image on disk and in the database write only the path of it, do not know if it is the best option, but it is an option.

  • How do I record to disc?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.