VS Report with image from database - cannot show image saved as varbinary
-
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.
-
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.
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.