none
Crystal Reports - Imagem em byte vinda do banco RRS feed

  • Pergunta

  • Pessoal tem um metodo de retornar a imagem do banco em byte e vice versa, porem nao estou conseguindo colocar ela em meu relatorio do cristal, ja tentei com parametros, adicionei um Picture e nada, vou posta o codigo para ver se conseguem esclarecer alguma coisa.

     void getImagensSQLServer(SqlConnection conexaoSQLServer)
            {
                try
                {
                    //Inicializar o SQL adapter.
                    SqlDataAdapter ADAP = new SqlDataAdapter("Select id,brasao,logo from tbPrefeitura", conexaoSQLServer);

                    //Inicializa o  Dataset.
                    DataSet DS = new DataSet();

                    //Preenche o dataset com a tabela Imagens
                    ADAP.Fill(DS, "tbPrefeitura");

                    //preenche o datagridviewe com o dataset.
                    dgvPrefeitura.DataSource = DS.Tables["tbPrefeitura"];
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

    public void showData()
            {
                con.Open();
                adp.Fill(ds);
                txtId.Text = ds.Tables[0].Rows[position][0].ToString();

                Image Image1 = null;
                Image Image2 = null;
                using (SqlConnection Conexao = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoContratos.Properties.Settings.BancoContratosConnectionString"].ConnectionString))
                {
                    Conexao.Open();
                    using (SqlCommand Comando = Conexao.CreateCommand())
                    {
                        Comando.CommandType = CommandType.Text;
                        Comando.CommandText = "SELECT * FROM tbPrefeitura WHERE id=@Id";
                        Comando.Parameters.Add("@id", SqlDbType.Int).Value = int.Parse(txtId.Text);
                        using (SqlDataReader Reader = Comando.ExecuteReader())
                        {
                            if (Reader.HasRows)
                            {
                                Reader.Read();
                                Image1 = ConvertByteArrayToImage((Reader["brasao"] as byte[]));
                                Image2 = ConvertByteArrayToImage((Reader["logo"] as byte[]));
                            }
                        }
                    }
                    Conexao.Close();
                }
                if (Image1 != null)
                {
                    picBrasao.Image = Image1;
                    picBrasao.Refresh();
                    picBrasao.Update();
                }
                if (Image2 != null)
                {
                    picLogo.Image = Image2;
                    picLogo.Refresh();
                    picLogo.Update();
                }

                con.Close();
            }

            public byte[] ConvertImageToByteArray(Image image, System.Drawing.Imaging.ImageFormat imageFormat)
            {
                if (image == null)
                    return null;
                MemoryStream ms = new MemoryStream();
                image.Save(ms, imageFormat);
                return ms.ToArray();
            }

            public Image ConvertByteArrayToImage(byte[] byteArray)
            {
                if (byteArray == null || byteArray.Length == 0)
                { return (null); }
                return (Image.FromStream(new MemoryStream(byteArray)));
            }

    Aguardo

    quinta-feira, 16 de janeiro de 2014 02:28

Todas as Respostas