0

I have checked stackoverflow, google, youtube, msdn resources. MSDN says, I need to use picturebox and use my database and set mime type. I've done this. But Image does not show.

How can I show any type of image i.e jpg, png etc from database to Microsoft Report RDLC? I've saved image into database as binary type.

ReportViewer.cs:

_connection.Open();
_aPatient = new Patient();

String QuearString = String.Format(
    "SELECT ImageReportStorageTable.ImageOne From ImageReportStorageTable " +
    " WHERE   (ImageReportStorageTable.PrescriptionCode = 21)");
String baseString=null;
_command = new SqlCommand(QuearString, _connection);
SqlDataReader aReader = _command.ExecuteReader();

if (aReader.HasRows)
{
    while (aReader.Read())
    {
        baseString = Convert.ToBase64String((byte[]) (aReader[0]));
    }
}
_connection.Close();

ReportParameter paramLogo = new ReportParameter();
paramLogo.Name = "Image1";
paramLogo.Values.Add(baseString);
prescriptionReportViewer.LocalReport.SetParameters(paramLogo);

I've used the returned value from the query above into report viewer image property function.

=System.Convert.FromBase64String(Parameters!Image1.Value) 
Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
  • for the future - I think, storing images to database is not a good ideea - http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay – Johnny Jan 01 '15 at 17:46
  • @Johnny: Well, the post you refer to, lists advantages and disadvantages for both approaches. – Olivier Jacot-Descombes Jan 01 '15 at 17:52
  • Maybe this post helps: [How can I render a PNG image (as a memory stream) onto a .NET ReportViewer report surface](http://stackoverflow.com/a/155600/880990). – Olivier Jacot-Descombes Jan 01 '15 at 18:11
  • I have tried according to that post. But my code doesn't reach to the converter method at all! It returns the report viewer window as soon as it sees the value of aReader assigned to baseString. – Mahfuzur Rahman Jan 02 '15 at 06:17

0 Answers0