Load BLOB for Image C # MySQL

2

I am trying to load a saved image into MySQL, however still unsuccessful. With the code below I can display all the other fields. Every time I try to add some method to display the image, an error occurs that does not display any search information.

MySqlConnection conn = new MySqlConnection("Server=localhost;Database=portaria;Uid=root;Pwd=''");
                conn.Open();

                //Inserindo um comando para acessar o funcionário cadastrado
                MySqlCommand consultar = new MySqlCommand(
                    "SELECT funcID, funcRG, funcNome, funcEmpresa, funcSetor, funcRamal, funcFoto, funcStatus " +
                    "FROM funcionario WHERE funcRG = ?", conn);

                consultar.Parameters.Clear();
                consultar.Parameters.Add("@funcRG",MySqlDbType.VarChar, 12).Value = txtRG.Text;
                consultar.CommandType = CommandType.Text;

                //Recebendo o conteúdo da pesquisa
                MySqlDataReader info;
                info = consultar.ExecuteReader();
                info.Read();

                //Passando as informações para os campos
                lblNumID.Text = info.GetString(0);
                txtNome.Text = info.GetString(2);
                txtEmpresa.Text = info.GetString(3);
                txtSetor.Text = info.GetString(4);
                txtFone.Text = info.GetString(5);
                //pictureCadastro.Text = info.GetString(6); ------>>>>> Falta carregar a imagem
                cBoxStatus.Text = info.GetString(7);

                conn.Close();

Can anyone help me?

    
asked by anonymous 03.12.2018 / 01:24

2 answers

0

I was able to solve my problem using the Code Project site link code.

    
06.12.2018 / 11:44
0

string base64string = info.GetString(6);
byte[] blobImage = Convert.FromBase64String(base64string);

using (MemoryStream ms = new MemoryStream(blobImage))
{
 pictureCadastro.Image = Image.FromStream(ms);
}
    
03.12.2018 / 10:38