Image Load From Database Cant Load

edited December 2017 in FastReport .NET
Hello everyone who codes. I have a winform appliacation uses Fast Report. In database i have bitmap column for storing image data as byte[]. So in fast report i need to some code works. I have and empty picturebox and i want it to fill with image data from database on creating report. Problem is that i am saving my report informations and after creating record, i will show informations in report works fine. After then if i would want to change to record i am opening record with modify and after modifiying i want to show report again and this time report does not work. Same code gives exception TargetInvocationException when i use report.Prepare() or report.Show()

Here is my code i used in report file

This is my converting function
public Bitmap ByteToImage(byte[] blob)
{
MemoryStream mStream = new MemoryStream();
byte[] pData = blob;
mStream.Write(pData, 0, Convert.ToInt32(pData.Length));
Bitmap bm = new Bitmap(mStream, false);
mStream.Dispose();
return bm;
}


private void _StartReport(object sender, EventArgs e)
{
Picture3.Image = (Image)ByteToImage(((Byte[])Report.GetColumnValue("Table.Resim"))) ;
}

Comments

  • edited December 2017
            private FastReport.Report report;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                report = new FastReport.Report();
                report.Preview = previewControl1;
                report.Load("reporttemplate.frx");
            }
    
            private void ShowReport(DataTable dataTable)
            {
                // to reflect changes, you must register/re-register data
                report.RegisterData(dataTable, "Table");
                report.Prepare();
                report.ShowPrepared();
            }
    


    attach bytearray image to pictureobject
    Byte[] image = (Byte[]) Report.GetColumnValue("Table.Resim");
    using (System.IO.Stream ms = new System.IO.MemoryStream(image, 0, image.Length))
    {
        Picture3.Image = Image.FromStream(ms, true);
    }
    

    BTW, have you ever tried this?
    bind picture3 using datacolumn property => Picture3.DataColumn = "Table.Resim"

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.