Upload photo from Datagridview and switch to picturebox C #

1

I'm having a hard time getting my photo taken and showing it in PictureBox

My scenario is as follows:

I have a Registration Form that inserts the data and A Form that performs the search of the record that is displayed in a DataGridView; Well I do the insertion of the data and the converted photo to binary, using the db sqlserverm ais to with difficulty in passing the photo to my picture, the other fields I can bring, but the photo does not.

Note: This is my first time working with a photo in WindowsForms.

follow my galley code.

< - This is from my DataGridView where I select the cell by throwing the data into the record form - >

private void dgw_Onibus_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        try
        {
            if (lblOperacao.Text == "Aluno Master")
            {

                DataGridViewRow dr = dgw_Onibus.SelectedRows[0];
                this.Hide();
                cg.ds = new DataSet();
                FRM_CadOnibusCircular frm = new FRM_CadOnibusCircular();
                frm.Show();

                frm.TB_id.Text = dr.Cells[0].Value.ToString();
                frm.TB_IdFicha.Text = dr.Cells[1].Value.ToString();
                frm.TB_NomeUser.Text = dr.Cells[2].Value.ToString();
                frm.MK_TelUser.Text = dr.Cells[3].Value.ToString();
                frm.TB_RgUser.Text = dr.Cells[4].Value.ToString();
                frm.MTK_CpfUser.Text = dr.Cells[5].Value.ToString();

                frm.TB_NomeProprietario.Text = dr.Cells[7].Value.ToString();
                frm.MK_TelProprietario.Text = dr.Cells[8].Value.ToString();
                frm.TB_EnderecoProprietario.Text = dr.Cells[9].Value.ToString();
                frm.TB_QdProprietario.Text = dr.Cells[10].Value.ToString();
                frm.TB_EmailProprietario.Text = dr.Cells[11].Value.ToString();
                frm.TB_RgProprietario.Text = dr.Cells[12].Value.ToString();
                frm.MKT_Proprietario.Text = dr.Cells[13].Value.ToString();
                frm.TB_NumeroProprietario.Text = dr.Cells[14].Value.ToString();
                frm.TB_LoteProprietario.Text = dr.Cells[15].Value.ToString();

                bool proprietarioChecked = dgw_Onibus.CurrentRow.Cells["opcao"].Value.ToString().Contains("Proprietario");
                bool depedenteChecked = dgw_Onibus.CurrentRow.Cells["Opcao"].Value.ToString().Contains("Depedente");
                bool colaboradorChecked = dgw_Onibus.CurrentRow.Cells["opcao"].Value.ToString().Contains("Colaborador"); // Ou contém "Yoga", não sei como você guarda isto na sua 'DataGridView'

                // Obter checkBoxlist da seleção

                int indexCbProprietario = GetItemIndex(frm.CLB_Opcao, "Proprietario");
                int indexCbDepedente = GetItemIndex(frm.CLB_Opcao, "Depedente");
                int indexCbColaborador = GetItemIndex(frm.CLB_Opcao, "Colaborador"); // fmr.chekedListBox é o nome do seu CheckedListBox dentro do seu form. 

                //Pegar o valor da dataGridView que diz se a determinada atividade está marcada





                // Checar o valor da Opcao no seu 'checkedListBox'
                frm.CLB_Opcao.SetItemChecked(indexCbProprietario, proprietarioChecked);
                frm.CLB_Opcao.SetItemChecked(indexCbDepedente, depedenteChecked);
                frm.CLB_Opcao.SetItemChecked(indexCbColaborador, colaboradorChecked);



                frm.BT_UpdateOnibus.Enabled = true;
                frm.BT_DeleteOnibus.Enabled = true;
                frm.BT_SaveOnibus.Enabled = false;
                frm.Lbl_Usuario.Text = lblUsuario.Text;
                lblOperacao.Text = "";
            }
        }
        catch (Exception erro)
        {
            MessageBox.Show(erro.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

I've tried it that way, but it did not work!

frm.picFoto.Image = null;

                if (ds.Tables[0].Rows[linhaNumero][6] != System.DBNull.Value)
                {
                    foto_array = (byte[])ds.Tables[0].Rows[linhaNumero][6];
                    MemoryStream ms = new MemoryStream(foto_array);
                    frm.picFoto.Image = Image.FromStream(ms);
                }

 int linhaNumero = 0;
    byte[] foto_array;

Note: "My column of the table where the photo is stored, it is defined as image, I had initially left as Varbinary, but I changed to tests." Thank you for your help!

    
asked by anonymous 10.08.2018 / 18:23

0 answers