Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Studio 2015 & .NET 4.6
  4. VS Report with image from database - cannot show image saved as varbinary

VS Report with image from database - cannot show image saved as varbinary

Scheduled Pinned Locked Moved Visual Studio 2015 & .NET 4.6
graphicshelpdatabasevisual-studiotutorial
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PrissySC
    wrote on last edited by
    #1

    I have an image element added to the report. I added the dataset and filled it on the form with the reportviewer control. The report and its datasource are correct. I set the image to the correct datafield and selected jpeg for the type. However, I know that I am missing something when it comes to pulling the image from the database - it was saved as a varbinary(max) because I was afraid to use image with all of the talk of this type being "done away with" in the future. I can pull the image to a picturebox on the form and load it with the following code ...

    cu = (From tbl In context.refCompanyUsers Select tbl).Single

    Dim img = cu.StampLogo

    LogoPictureBox.Image = ConvertBinaryToImage(img.ToArray())

    I know I need to do something similar to show the image on the report, but all of my MS and Google searches do not return how to directly use the code or parameter in some such manner to display this needed element. I hate that I have to say it, but I do not know how. :wtf: And, to make matters worse, I can't find it myself in the knowledge base, which is usualy never a problem. :(( More to add: I have written the custom code for the report:

    Public Function ConvertImageByte(ByVal img As Byte()) as System.Drawing.Bitmap
    Dim picStream As System.IO.MemoryStream
    Dim logo As System.Drawing.Bitmap = 
                New System.Drawing.Bitmap(System.Drawing.Image.FromStream(picStream))
    	
    Return logo
    End Function
    

    I use this in the picture box on the report designer:

    Code.ConvertImageByte(system.Convert.ChangeType((First(Fields!StampLogo.Value, "CompanyUserDataSet")),GetType(Byte())))

    The "ConvertImageByte" has the red, wavy error line under it. While I have made some progress. I still have no image. The last bit of code is my latest attempt at using a stream reader versus converting or casting.

    P 1 Reply Last reply
    0
    • P PrissySC

      I have an image element added to the report. I added the dataset and filled it on the form with the reportviewer control. The report and its datasource are correct. I set the image to the correct datafield and selected jpeg for the type. However, I know that I am missing something when it comes to pulling the image from the database - it was saved as a varbinary(max) because I was afraid to use image with all of the talk of this type being "done away with" in the future. I can pull the image to a picturebox on the form and load it with the following code ...

      cu = (From tbl In context.refCompanyUsers Select tbl).Single

      Dim img = cu.StampLogo

      LogoPictureBox.Image = ConvertBinaryToImage(img.ToArray())

      I know I need to do something similar to show the image on the report, but all of my MS and Google searches do not return how to directly use the code or parameter in some such manner to display this needed element. I hate that I have to say it, but I do not know how. :wtf: And, to make matters worse, I can't find it myself in the knowledge base, which is usualy never a problem. :(( More to add: I have written the custom code for the report:

      Public Function ConvertImageByte(ByVal img As Byte()) as System.Drawing.Bitmap
      Dim picStream As System.IO.MemoryStream
      Dim logo As System.Drawing.Bitmap = 
                  New System.Drawing.Bitmap(System.Drawing.Image.FromStream(picStream))
      	
      Return logo
      End Function
      

      I use this in the picture box on the report designer:

      Code.ConvertImageByte(system.Convert.ChangeType((First(Fields!StampLogo.Value, "CompanyUserDataSet")),GetType(Byte())))

      The "ConvertImageByte" has the red, wavy error line under it. While I have made some progress. I still have no image. The last bit of code is my latest attempt at using a stream reader versus converting or casting.

      P Offline
      P Offline
      PrissySC
      wrote on last edited by
      #2

      Actually, it was a matter of expected type. System.Binary[] I set up an empty data class (linq2sql) with a column called image. It is not connected to any SQL data table. I made the column type System.Binary[] Important note is that primary key is not needed either. It is more or less a "dummy" object for the purpose of being able to send via a bindingsource to a dataset to fill using the report viewer and rdlc report designer. Add the object to the data sources. I filled it from the company table (stored in SQL field varbinary(max)) by getting the only row, or first, in a select. I added a binding source for the empty class (ImageTable or ImageClass). Like this ... Dim imageInfo as New AppName.ImageClass Dim temp as New AppName.CompanyTable temp = (From table in context.CompanyTable Select s).FirstorDefault imageInfo.ShowImage = temp.ColumnNameWithImage.ToArray BindingSource.Datasource = imageInfo The dataset for the empty class was added to the report. The source in the report viewer is the binding source. Weird, but it was all because of "type". Combine this with the issue of being able to send in a dataset and it was a bit boggling. Hope this helps someone else. :) From where I started, I got the code down to five lines. I needed this to be streamlined as the entire app is reporting based on barcode and date for status and production.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups