To display image from SQL server into crystal report


In this article I will explain how to display images in crystal report using SQL server. Many developers are needing this requirement. This code is also helpful for MS Access database in which the data type must be taken as OLE object. For MS SQL Server data type as image.

Sometimes it is necessary to use images in crystal report. Some of the crystal report versions are not supporting the images, so it is necessary to display image.

In this article, I show the image is store in SQL database in bytes or in binary format. So crystal report is capable to extract that image directly using the method of dataset as datasource for crystal report.



Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim imgbytes As Byte() = Nothing
imgbytes = IO.File.ReadAllBytes(OpenFileDialog1.FileName)

Dim scon As New SqlConnection("PATH")
Dim cmd As SqlCommand
cmd = New SqlCommand("insert into detail values(@id,@img)", scon)
cmd.Parameters.AddWithValue("@id", TextBox2.Text)
cmd.Parameters.AddWithValue("@img", imgbytes)

scon.Open()
cmd.ExecuteNonQuery()
scon.Close()

End Sub



This is sample of code to convert image to binary format.
I am attaching sample of this application with this article also.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: